沿Google Map Android中的路径对汽车(标记)进行动画处理 [英] Animate a car(Marker) along a path in google map android
本文介绍了沿Google Map Android中的路径对汽车(标记)进行动画处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果有List,我将分享一种在路径上移动标记的解决方案.位图将通过使用LatLng列表沿路径移动.
I am going to share a solution of moving a marker along the path if you have List.The Bitmap will move along the path from using LatLng list.
推荐答案
public static void setAnimation(GoogleMap myMap, final List<LatLng> directionPoint, final Bitmap bitmap) {
Marker marker = myMap.addMarker(new MarkerOptions()
.icon(BitmapDescriptorFactory.fromBitmap(bitmap))
.position(directionPoint.get(0))
.flat(true));
myMap.animateCamera(CameraUpdateFactory.newLatLngZoom(directionPoint.get(0), 10));
animateMarker(myMap, marker, directionPoint, false);
}
private static void animateMarker(GoogleMap myMap, final Marker marker, final List<LatLng> directionPoint,
final boolean hideMarker) {
final Handler handler = new Handler();
final long start = SystemClock.uptimeMillis();
Projection proj = myMap.getProjection();
final long duration = 30000;
final Interpolator interpolator = new LinearInterpolator();
handler.post(new Runnable() {
int i = 0;
@Override
public void run() {
long elapsed = SystemClock.uptimeMillis() - start;
float t = interpolator.getInterpolation((float) elapsed
/ duration);
if (i < directionPoint.size())
marker.setPosition(directionPoint.get(i));
i++;
if (t < 1.0) {
// Post again 16ms later.
handler.postDelayed(this, 16);
} else {
if (hideMarker) {
marker.setVisible(false);
} else {
marker.setVisible(true);
}
}
}
});
}
这篇关于沿Google Map Android中的路径对汽车(标记)进行动画处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文