Skip to content Skip to sidebar Skip to footer

Animating Markers On Openstreet Maps Using Osmdroid

I'm using the google Maps marker animation logic given here. My marker gets animated,but after each marker.setPosition(newPosition); I need to call mapView.invalidate();which refre

Solution 1:

The next solution is working correctly for me:

import org.osmdroid.api.IGeoPoint;
import org.osmdroid.api.IMapController;
import org.osmdroid.util.GeoPoint;
import org.osmdroid.views.MapView;
import org.osmdroid.views.Projection;
import org.osmdroid.views.overlay.Marker;

publicvoidanimateMarker(final Marker marker, final GeoPoint toPosition) {
    finalHandlerhandler=newHandler();
    finallongstart= SystemClock.uptimeMillis();
    Projectionproj= map.getProjection();
    PointstartPoint= proj.toPixels(marker.getPosition(), null);
    finalIGeoPointstartGeoPoint= proj.fromPixels(startPoint.x, startPoint.y);
    finallongduration=500;
    finalInterpolatorinterpolator=newLinearInterpolator();
    handler.post(newRunnable() {
        @Overridepublicvoidrun() {
            longelapsed= SystemClock.uptimeMillis() - start;
            floatt= interpolator.getInterpolation((float) elapsed / duration);
            doublelng= t * toPosition.getLongitude() + (1 - t) * startGeoPoint.getLongitude();
            doublelat= t * toPosition.getLatitude() + (1 - t) * startGeoPoint.getLatitude();
            marker.setPosition(newGeoPoint(lat, lng));
            if (t < 1.0) {
                handler.postDelayed(this, 15);
            }
            map.postInvalidate();
        }
    });
}

It is based on the same implementation done by some people for GoogleMaps v2, but adapted to osmdroid.

The source where I found the implementation for GoogleMaps v2 is here: How to animate marker in android map api V2?

I am using: osmdroid-android 5.5 and osmbonuspack 6.0

Post a Comment for "Animating Markers On Openstreet Maps Using Osmdroid"