有谁知道这个动画的实现如何在 google map api v2 中实现。 在这里查看。 我想知道这是怎么做到的。如果有人对此有任何示例代码,请告诉我。
提前致谢。
有谁知道这个动画的实现如何在 google map api v2 中实现。 在这里查看。 我想知道这是怎么做到的。如果有人对此有任何示例代码,请告诉我。
提前致谢。
我找到了一个适合我的解决方案:
final LatLng target = NEW_LOCATION;
final long duration = 400;
final Handler handler = new Handler();
final long start = SystemClock.uptimeMillis();
Projection proj = map.getProjection();
Point startPoint = proj.toScreenLocation(marker.getPosition());
final LatLng startLatLng = proj.fromScreenLocation(startPoint);
final Interpolator interpolator = new LinearInterpolator();
handler.post(new Runnable() {
@Override
public void run() {
long elapsed = SystemClock.uptimeMillis() - start;
if (elapsed > duration) {
elapsed = duration;
}
float t = interpolator.getInterpolation((float) elapsed / duration);
double lng = t * target.longitude + (1 - t) * startLatLng.longitude;
double lat = t * target.latitude + (1 - t) * startLatLng.latitude;
marker.setPosition(new LatLng(lat, lng));
if (t < 1.0) {
// Post again 10ms later.
handler.postDelayed(this, 10);
} else {
// animation ended
}
}
});
Marker
欢迎您随时通过调用来更改 a 的位置setPosition()
。欢迎您使用或on应用CameraUpdate
对象,随时更改“相机”的位置(即地图的中心和缩放级别)。将这些与光定时循环(例如,使用)结合起来应该可以让您实现类似的动画效果。moveTo()
animateTo()
GoogleMap
postDelayed()
好消息是他的 Google Map API v2 提供了新的相机控件。 您可以在 Android 开发人员团队的 Youtube 频道上直接查看新功能以及如何使用它们。
它还提供动画、倾斜、方位……但我认为该视频非常详细,并且还讨论了您示例中的应用程序。
玩得开心,完成应用后给我一个链接。