title: Android : Unable to animate marker from one position to another in Google maps
body: <p>Hello I am trying to update the marker from one position to another in google maps. I want to change the location of the marker with animation just like uber &amp; Ola . Sample code below. I am not getting any error. I am just not seeing the animation.  Any simple animation will do. </p>
  
  <p><strong>Code</strong></p>
  
  <pre><code>public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {
  
      private GoogleMap mMap;
      private static int SPLASH_TIME_OUT = 5000;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_maps);
          // Obtain the SupportMapFragment and get notified when the map is ready to be used.
          SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
                  .findFragmentById(R.id.map);
          mapFragment.getMapAsync(this);
      }
  
  
  
      @Override
      public void onMapReady(GoogleMap googleMap) {
          mMap = googleMap;
  
          // Add a marker in tilak nagar
          LatLng tilkanagar = new LatLng(28.6353, 77.0971);
  
          LatLng Firstmarker = new LatLng(28.6350, 77.0970);
          LatLng FirstmarkerTo = new LatLng(28.6356, 77.0972);
  
          LatLng Secondmarker = new  LatLng(28.6345, 77.0969);
          LatLng SecondmarkerTo = new LatLng(28.6347, 77.0967);
  
  
          mMap.addMarker(new MarkerOptions().position(tilkanagar).title("Hello I am at Techvision"));
          Marker marker = mMap.addMarker(new MarkerOptions().position(Firstmarker).title("1 Minute Away").icon(BitmapDescriptorFactory.fromResource(R.drawable.car)));
          Marker marker1 = mMap.addMarker(new MarkerOptions().position(Secondmarker).title("2 Minutes Away").icon(BitmapDescriptorFactory.fromResource(R.drawable.car)));
  
  
          mMap.moveCamera(CameraUpdateFactory.newLatLng(tilkanagar));
          mMap.animateCamera(CameraUpdateFactory.zoomTo(18.0f));
  
  
                      animateMarker(marker, FirstmarkerTo, false);
                      animateMarker(marker1,SecondmarkerTo,false);
  
      }
  
  
      public void animateMarker(final Marker marker, final LatLng toPosition,
                                final boolean hideMarker) {
  
          Thread background = new Thread() {
              public void run() {
  
                  try {
                      // Thread will sleep for 5 seconds
                      sleep(5*1000);
  
                      // After 5 seconds redirect to another intent
                      final Handler handler = new Handler();
                      final long start = SystemClock.uptimeMillis();
                      Projection proj = mMap.getProjection();
                      Point startPoint = proj.toScreenLocation(marker.getPosition());
                      final LatLng startLatLng = proj.fromScreenLocation(startPoint);
                      final long duration = 500;
  
                      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 * toPosition.longitude + (1 - t)
                                      * startLatLng.longitude;
                              double lat = t * toPosition.latitude + (1 - t)
                                      * startLatLng.latitude;
                              marker.setPosition(new LatLng(lat, lng));
  
                              if (t &lt; 1.0) {
                                  // Post again 16ms later.
                                  handler.postDelayed(this, 16);
                              } else {
                                  if (hideMarker) {
                                      marker.setVisible(false);
                                  } else {
                                      marker.setVisible(true);
                                  }
                              }
                          }
                      });
  
                      //Remove activity
                      finish();
  
                  } catch (Exception e) {
  
                  }
              }
          };
  
          // start thread
          background.start();
  
              }
  }
  </code></pre>
  
  <p><strong>Output</strong></p>
  
  <p><a href="https://i.stack.imgur.com/vnL0A.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/vnL0A.png" alt="enter image description here"></a></p>