移动标记顺利android地图

时间:2016-08-31 11:55:26

标签: android google-maps android-layout google-maps-markers

我有一个坐标列表,我想在折线上移动我的标记。我已经创建了折线,我也可以移动标记,但它不是很平滑。它只是从一个坐标移动到另一个坐标。

我使用的代码是我在互联网上找到的代码。

public void setAnimation(GoogleMap myMap, final List<LatLng> directionPoint, final Bitmap bitmap) {

    Marker marker = myMap.addMarker(new MarkerOptions()
            .icon(BitmapDescriptorFactory.fromBitmap(bitmap))
            .position(directionPoint.get(0))
            .title(Speed.get(0))
            .flat(true));
    System.out.println("SIZZEE: " + Speed.size() + ", " + directionPoint.size());
    marker.showInfoWindow();

    animateMarker(myMap, marker, directionPoint, true);
}


private void animateMarker(final GoogleMap myMap, final Marker marker, final List<LatLng> directionPoint,
                           final boolean hideMarker) {
    final Handler handler = new Handler();
    final long start = SystemClock.uptimeMillis();
    Projection proj = myMap.getProjection();
    final long duration = 30000;

    final Interpolator interpolator = new LinearInterpolator();
     handler.post(new Runnable() {
        int i = 0;


        @Override
        public void run() {
            long elapsed = SystemClock.uptimeMillis() - start;
            float t = interpolator.getInterpolation((float) elapsed
                    / duration);
            if (i < directionPoint.size()) {
                marker.setPosition(directionPoint.get(i));
                marker.setTitle(Speed.get(i) + "Km/h");
                marker.showInfoWindow();
                myMap.moveCamera(CameraUpdateFactory.newLatLngZoom(directionPoint.get(i) , 17.0f));

            }
            i++;


            if (t < 1.0) {
                // Post again 16ms later.
                handler.postDelayed(this, 500);
            } else {
                if (hideMarker) {
                    marker.setVisible(false);
                } else {
                    marker.setVisible(true);
                }
            }
        }
    });
}

我能做些什么才能使标记移动得非常顺畅?

0 个答案:

没有答案