谷歌地图 v2 标记动画 [英] Google Map v2 Marker Animation

查看:29
本文介绍了谷歌地图 v2 标记动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有人知道如何在 google map api v2 中实现这个动画?在这里查看.我想知道这是如何完成的.如果有人有任何关于此的示例代码,请告诉我.

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

这篇关于谷歌地图 v2 标记动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆