0

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)


    );

1 Answers1

0

You will find your answer in this question Answer : Draw path between two points using Google Maps Android API v2 you will use the API to get the Points between the two Location then use them to animate your marker

Community
  • 1
  • 1
3bdoelnaggar
  • 1,109
  • 8
  • 18