谷歌地图V2标记动画标记、地图、动画

2023-09-04 03:09:01 作者:四肢僵硬没人在深夜买醉

做任何人有想法这部动画的实现如何可能在谷歌地图API第2版。 看看这个在这里。 我想知道如何做到这一点。请让我知道,如果任何人有这方面的任何样本code。

Do anyone have idea how this animation's implementation is possible in google map api v2. Check out this here. I would like to know how this is done. Please let me know if anyone have any sample code regarding this.

在此先感谢。

推荐答案

我发现,工作对我来说是解决方案:

I found a solution that worked for me:

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;
        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
        }
    }
});