I modified the same method to achieve this.
We need to call this method
animateMarker(googleMap, driver, arrayPoints, distance(arrayPoints.get(0), arrayPoints.get(1)) * msForKMTravel, 0);
arrayPoints is the LatLng array. msForKMTravel is the microSec for travlling a KM.
Method :::
public void animateMarker(final GoogleMap mMap, final Marker marker, final List<LatLng> arrayLications, final double duration, final int step) {
Log.d(TAG, "Moving from:" + step + "To:" + (step + 1) + "duration" + duration);
final Handler handler = new Handler();
final long start = SystemClock.uptimeMillis();
LatLng startPosition = arrayLications.get(step);
final LatLng toPosition = arrayLications.get(step + 1);
Projection proj = mMap.getProjection();
Point startPoint = proj.toScreenLocation(startPosition);
final LatLng startLatLng = proj.fromScreenLocation(startPoint);
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));
Log.d(TAG, "interpolator t:" + t + "start :" + start + " elapsed :" + elapsed);
double lng = t * toPosition.longitude + (1 - t)
* startLatLng.longitude;
double lat = t * toPosition.latitude + (1 - t)
* startLatLng.latitude;
LatLng newLatLng = new LatLng(lat, lng);
Log.d(TAG, "Moving to" + newLatLng);
marker.setPosition(newLatLng);
if (t < 1.0) {
handler.postDelayed(this, 100);
} else {
if (arrayLications.size() > step + 2 && isVisible()) {
double distance = distance(arrayLications.get(step + 1), arrayLications.get(step + 2));
double time = distance * msForKMTravel;
Log.d(TAG, "Go for distance" + distance + " in time " + time);
animateMarker(mMap, marker, arrayLications, time, step + 1);
}
}
}
});
}