这是在谷歌地图中的表现
我认为这也应该适用于你的情况......或者至少你会明白
如果你有所有 lat lng ... 循环遍历列表并有一些延迟,然后将动画应用于标记
这里是代码 sn-p 如果你想我可以发布整个逻辑
// animate marker between two points to avoid jumpimg or shaking movement of marker while playing trip
private void moveMarkerPlay(double lat, double lng, Marker marker, double latNew, double lngNew) {
marker.setRotation((float) bearingBetweenLocations(new LatLng(lat, lng), new LatLng(latNew, lngNew)));
animateMarkerToICS(marker, new LatLng(latNew, lngNew), new LatLngInterpolator.Spherical());
if (playCount % (5 * playSpeed) == 0) {
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(latNew, lngNew), mMap.getCameraPosition().zoom));
}
}
public static ObjectAnimator animator;
public void animateMarkerToICS(Marker marker, LatLng finalPosition, final LatLngInterpolator latLngInterpolator) {
TypeEvaluator<LatLng> typeEvaluator = (fraction, startValue, endValue) -> latLngInterpolator.interpolate(fraction, startValue, endValue);
Property<Marker, LatLng> property = Property.of(Marker.class, LatLng.class, "position");
animator = ObjectAnimator.ofObject(marker, property, typeEvaluator, finalPosition);
animator.setDuration(330 / playSpeed);
animator.start();
}
//Calculate bearing (angle) between two lat lng used for rotating marker as car moves
private double bearingBetweenLocations(LatLng latLng1, LatLng latLng2) {
double PI = 3.14159;
double lat1 = latLng1.latitude * PI / 180;
double long1 = latLng1.longitude * PI / 180;
double lat2 = latLng2.latitude * PI / 180;
double long2 = latLng2.longitude * PI / 180;
double dLon = (long2 - long1);
double y = Math.sin(dLon) * Math.cos(lat2);
double x = Math.cos(lat1) * Math.sin(lat2) - Math.sin(lat1)
* Math.cos(lat2) * Math.cos(dLon);
double brng = Math.atan2(y, x);
brng = Math.toDegrees(brng);
brng = (brng + 360) % 360;
return brng;
}