android - 如何删除折线中的行进部分并像 uber,swiggy 一样对其进行动画处理?
问题描述
我有一个疑问,但这可能会多次回答,但我找不到任何解决方案。我的疑问是如何像 uber 那样在折线上为标记设置动画现在让我详细解释一下,我经常从服务器上拉长,基于此我需要删除折线的行进部分并对其进行动画处理,现在让我发布我尝试过的内容远的。
这是我经常拉长的方法
public void UpdatePolyline(Double lat_decimal,Double lng_decimal){
List<LatLng>removedline=new ArrayList<>();
float distance=60.0f;
if (polylineLatlng.size()>0){
for (int i = 0; i < polylineLatlng.size(); i++) {
if (polylineLatlng.size()>0) {
try {
float smallest_distance=CalculationByDistance(polylineLatlng.get(i),new LatLng(lat_decimal, lng_decimal));
if (smallest_distance<distance){
removedline.add(polylineLatlng.get(i));
polylineLatlng.remove(i);
distance=smallest_distance;
}
}catch (Exception ex){
ex.printStackTrace();
break;
}
}
else {
break;
}
}
}
if (mpolyline != null) {
if (polylineLatlng.size() > 0) {
mpolyline.setPoints(polylineLatlng);
for (int i=0;i<removedline.size();i++){
Location location = new Location("");
location.setLatitude(removedline.get(i).latitude);
location.setLongitude(removedline.get(i).longitude);
setDriverMarker(location);
}
}
else {
Location location = new Location("");
location.setLatitude(lat_decimal);
location.setLongitude(lng_decimal);
setDriverMarker(location);
}
}}}
private void setDriverMarker(Location latLng) {
if (latLng != null) {
if (markerDriver == null) {
RideMarker(latLng.getLatitude(),latLng.getLongitude());
} else {
move(markerDriver,latLng);
}
}}
public void move( final Marker marker, final Location toPosition) {
if (fromPosition != null && marker != null && toPosition != null) {
final Handler handlerRotation = new Handler();
final long startAngle = SystemClock.uptimeMillis();
final float startRotation = marker.getRotation();
final long durationRotation = 300;
final Interpolator interpolatorRotation = new LinearInterpolator();
float bearing = fromPosition.bearingTo(toPosition);
// Print.e("Bearing:" + bearing);
angle = bearing<0?(360+bearing):bearing;
angle = angle%360f;
// Print.e("Angle:" + angle);
handlerRotation.post(new Runnable() {
@Override
public void run() {
long elapsed = SystemClock.uptimeMillis() - startAngle;
float t = interpolatorRotation.getInterpolation((float) elapsed / durationRotation);
float rot = t * angle + (1 - t) * startRotation;
float mAngle = -rot > 180 ? rot / 2 : rot;
marker.setRotation(mAngle);
if (t < 1.0) {
handlerRotation.postDelayed(this, 16);
} else {
final Handler handler = new Handler();
final long start = SystemClock.uptimeMillis();
Projection projection = map.getProjection();
Point startPoint = projection.toScreenLocation(marker.getPosition());
final LatLng startLatLng = projection.fromScreenLocation(startPoint);
final long duration = 1000;
final Interpolator interpolator = new LinearInterpolator();
handler.post(new Runnable() {
@Override
public void run() {
long elapsed = SystemClock.uptimeMillis() - start;
float t = interpolator.getInterpolation((float) elapsed
/ duration);
double lng = t * toPosition.getLongitude() + (1 - t)
* startLatLng.longitude;
double lat = t * toPosition.getLatitude() + (1 - t)
* startLatLng.latitude;
marker.setPosition(new LatLng(lat, lng));
map.moveCamera(CameraUpdateFactory.newCameraPosition(new CameraPosition.Builder()
.target(new LatLng(toPosition.getLatitude(),toPosition.getLongitude()))
.zoom(map.getCameraPosition().zoom)
.build()));
if (t < 1.0) {
// Post again 16ms later.
handler.postDelayed(this, 16);
}
}
});
}
}
});
}
fromPosition = toPosition;
}
但我无法在它上面设置动画标记,甚至折线的行进部分也没有删除如何做到这一点,请任何人分享这个我正在努力解决这个问题,谢谢!
解决方案
推荐阅读
- google-colaboratory - 如何运行直到在 google colab 中选择包含的单元格?
- c# - sqlparameters.Add(或 AddWithValue)的结果
- spring-boot - Vaadin 14 Spring Boot App 从 ProductionMode 的命令行运行
- azure-data-factory - ADF - 将 csv 从源复制到目标,如果它在 2 天内完成并实现较旧的目标版本
- linux - 如何在 csh 脚本中忽略第一行并从第二行文本文件中读取和存储值
- python - 无法在珊瑚开发板上运行 edgetpu 检测
- python - Django allauth 设置会话参数并在登录后获取它们的问题
- python - 用于从数据集中过滤数据的 Python pandas 或 lambda 实用程序
- javascript - 从 reduce [Angular] 返回对象
- python - Selenium 缺少文本值