我已经开发了一个 android 应用程序,它显示了 latlng 将在 locationchanged 上保存到服务器的附近车辆,这将是 jsonarray 结果,我将能够通过动画在 mapbox 地图上添加标记我能够移动单个标记到下一个更新的 latlng 值。我无法在更新时同时移动地图导航视图上显示的所有标记。标记一一移动到更新的位置
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);
}
}
}