如何动画标记在地图Android的API V2? [英] How to animate marker in android map api V2?

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

问题描述

我要实现顺利过渡到模拟赛车运动的标记在地图上。

是否有可能在Android的地图API第2版的动画标记?

解决方案

试试下面的code对谷歌地图V2标志动画。 你需要使用插补类应用动画上的标记和处理它的处理程序如下动画:

 公共无效animateMarker(最终标记标记,最后的经纬度toPosition,
        最终布尔hideMarker){
    最终的处理程序处理程序=新的处理程序();
    最终长开始= SystemClock.uptimeMillis();
    投影PROJ = mGoogleMapObject.getProjection();
    点的startPoint = proj.toScreenLocation(marker.getPosition());
    最后的经纬度startLatLng = proj.fromScreenLocation(的startPoint);
    最后,持续时间长= 500;
    最终插补插补器=新LinearInterpolator();
    handler.post(新的Runnable(){
        @覆盖
        公共无效的run(){
            经过长= SystemClock.uptimeMillis() - 启动;
            浮动T = interpolator.getInterpolation((浮点)经过
                    /持续时间);
            双LNG = T * toPosition.longitude +(1  -  T)
                    * startLatLng.longitude;
            双纬度= T * toPosition.latitude +(1  -  T)
                    * startLatLng.latitude;
            marker.setPosition(新经纬度(纬度,经度));
            如果(T< 1.0){
                //邮稍后再为16ms。
                handler.postDelayed(这一点,16);
            } 其他 {
                如果(hideMarker){
                    marker.setVisible(假);
                } 其他 {
                    marker.setVisible(真正的);
                }
            }
        }
    });
}
 

I want to implement smooth transition to emulate car marker moving on the map.

Is it possible to animate marker in android map api v2?

解决方案

Try out the below code to animate the marker on Google Map V2. You need to use the Interpolator class to apply the animation on the Marker and handle it in the Handler for the animation as below:

   public void animateMarker(final Marker marker, final LatLng toPosition,
        final boolean hideMarker) {
    final Handler handler = new Handler();
    final long start = SystemClock.uptimeMillis();
    Projection proj = mGoogleMapObject.getProjection();
    Point startPoint = proj.toScreenLocation(marker.getPosition());
    final LatLng startLatLng = proj.fromScreenLocation(startPoint);
    final long duration = 500;
    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.longitude + (1 - t)
                    * startLatLng.longitude;
            double lat = t * toPosition.latitude + (1 - t)
                    * startLatLng.latitude;
            marker.setPosition(new LatLng(lat, lng));
            if (t < 1.0) {
                // Post again 16ms later.
                handler.postDelayed(this, 16);
            } else {
                if (hideMarker) {
                    marker.setVisible(false);
                } else {
                    marker.setVisible(true);
                }
            }
        }
    });
}

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

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