i am creating google map with multiple markers.Now i want to move a car icon between that markers.Using this Move markers in google map v2 android
I can move a car icon between from first point to second point.But it is not moving from second to third.When i used for loop for this it strightly goes to final point.I added delay also but nothing else worked for me.
Thanks in advance.
This is my code::
public void setAnimation(GoogleMap myMap, final List<LatLng> directionPoint) {
anim_map = myMap;
anim_marker = myMap.addMarker(new MarkerOptions()
.icon(BitmapDescriptorFactory.fromResource(R.drawable.bus_icon))
.position(directionPoint.get(0))
.flat(true));
myMap.animateCamera(CameraUpdateFactory.newLatLngZoom(directionPoint.get(0), 10));
if (directionPoint.size() >= 2) {
for (int i = 0; i < directionPoint.size() - 1; i++) {
h.post(new Runnable() {
@Override
public void run() {
animateMarker(anim_map, anim_marker, directionPoint, false);
}
});
}
}
}
private void animateMarker(GoogleMap myMap, final Marker marker, final List<LatLng> directionPoint,
final boolean hideMarker) {
final long start = SystemClock.uptimeMillis();
final long duration = 350000;
final Interpolator interpolator = new LinearInterpolator();
h.post(new Runnable() {
int i = 0;
@Override
public void run() {
long elapsed = SystemClock.uptimeMillis() - start;
float t = interpolator.getInterpolation((float) elapsed
/ duration);
// Log.e("T Location", t + "");
double lng = t * directionPoint.get(i + 1).longitude + (1 - t) * directionPoint.get(i).longitude;
double lat = t * directionPoint.get(i + 1).latitude + (1 - t) * directionPoint.get(i).latitude;
marker.setPosition(new LatLng(lat, lng));
if (t < 1.0) {
h.postDelayed(this, 1);
} else {
if (hideMarker) {
marker.setVisible(false);
} else {
marker.setVisible(true);
}
}
}
});
}