I have developed an android application which shows the near by vehicles for which latlng will be saved to server on locationchanged which will be the jsonarray result from which i will be able to add the markers on mapbox map through animation i am able to move the single marker to the next updated latlng values. I am not able to move all the markers displayed on the navigation view of the map simultaneously as they are updated. Marker moves one by one to the updated location
HashMap<Integer, Marker> markerhash = new HashMap<Integer, Marker>();
if (json.getString("status").equalsIgnoreCase("success")) {
Alllocations = json.getJSONArray("locations");
for (int i = 0; i < Alllocations.length(); i++) {
JSONObject LocInfo = Alllocations.getJSONObject(i);
int id = LocInfo.getInt("user_id");
if (markerhash.containsKey(id)) {
marker = markerhash.get(id);
marker.setIcon(icon);
ValueAnimator markerAnimator = ValueAnimator.ofObject(new LatLngEvaluator(), (Object[]) new LatLng[] {marker.getPosition(), new LatLng(LocInfo.getDouble("latitude"), LocInfo.getDouble("longitude"))});
markerAnimator.setDuration(2000);
markerAnimator.setInterpolator(new AccelerateDecelerateInterpolator());
markerAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
if (marker != null) {
marker.setPosition((LatLng) animation.getAnimatedValue());
}
}
});
markerAnimator.start();
} else {
marker = navigationView.getMapboxMap().addMarker(new MarkerOptions()
.position(new LatLng(LocInfo.getDouble("latitude"), LocInfo.getDouble("longitude")))
.snippet(String.valueOf(LocInfo.getInt("user_id")))
.icon(icon)
);
markerhash.put(id, marker);
}
}
}