I do have this following for loop
The array sections has a list of locations "LatLng" for each section inside the loop i'm calling animateMarker which animate the marker in my map like 2 sec
My problem is that this loop goes so fast that I can't even see the animate for each section . it just show the last section from the array and also sometimes it freez the app
The animatemarker has a hundler inside it with post delay
I want to see each animateMarker for each section in my loop I'm nooby with threads so I really do need help
Problem here
ArrayList<LatLng> sections = gd.getSection(mDoc);
for (int j = 0; j < sections.size(); j++) {
animateMarker(busMarker, new LatLng(sections.get(j).latitude, sections.get(j).longitude), false);
}
my animateMarker ( has no problem works fine ! )
public void animateMarker(final Marker marker, final LatLng toPosition,
final boolean hideMarker) {
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 = 2000;
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 < 1.0) {
// Post again 16ms later.
handler.postDelayed(this, 16);
} else {
if (hideMarker) {
marker.setVisible(false);
} else {
marker.setVisible(true);
}
}
}
});
}