通过折线在正确的开启路线上移动源到目标位置之间的标记

时间:2015-06-05 13:39:11

标签: android

我有当前的位置标记,靠近地方标记。我必须将当前位置标记移动到目标位置。

但我当前的位置标记正在移出多边形线。它不会在多线路径上移动。任何人都建议正确的解决方案。请事先谢谢

我在地图上移动标记的代码

public void animateMarker(final Marker marker,final LatLng toPosition,final boolean hideMarker)

{
    final Handler handler = new Handler();
    final long start = SystemClock.uptimeMillis();
    Projection proj = googleMap.getProjection();
    Point startPoint = proj.toScreenLocation(marker.getPosition());

    final long duration =1000;
    final LinearInterpolator interpolator = new  LinearInterpolator();
    handler.post(new Runnable()
    {


        public void run()

{

            long elapsed = SystemClock.uptimeMillis() - start;
            float t = interpolator.getInterpolation((float) elapsed
                    / duration);




            double lng = t * latlng_value.longitude + (1 - t)
                    * latlng.longitude;
            double lat = t * latlng_value.latitude + (1 - t)
                    * latlng.latitude;






            marker.setPosition(new LatLng(lat, lng));





            if (t < 1.0) 
            {



                  // Post again 16ms later.
                  handler.postDelayed(this, 10);  
            } 
            else 
            {


                if (hideMarker) 
                {
                    marker.setVisible(false);
                }
                else
                {
                    marker.setVisible(true);
                }
            }
        }
    });
}

1 个答案:

答案 0 :(得分:0)

我会查看代码:http://ddewaele.github.io/GoogleMapsV2WithActionBarSherlock/part3 这是一个非常好的例子,基本上你必须为折线的每个“子线”连接一组动画。

要获得该行的子路径,您可以使用具有插值函数的库“google-maps-utils”