I'm trying to move a marker on google maps with a driving route. I managed to animate the marker on the map but I couldn't move it according to a specific route. any help is appreciated thanks in advance. This is the code I used to animate the marker:
final long duration = 11200;
final Handler handler = new Handler();
final long start = SystemClock.uptimeMillis();
Projection proj = googleMap.getProjection();
Point startPoint = proj.toScreenLocation(marker.getPosition());
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);
double lng = t * target.longitude + (1 - t) * startLatLng.longitude;
double lat = t * target.latitude + (1 - t) * startLatLng.latitude;
LatLng posetion2=new LatLng(lat,lng);
CameraPosition cameraPosition =
new CameraPosition.Builder()
.target(posetion2)
.bearing(9)
.tilt(10)
.zoom(googleMap.getCameraPosition().zoom)
.build();
googleMap.animateCamera(
CameraUpdateFactory.newCameraPosition(cameraPosition)
);