Cách sử dụng Ví dụ cho DiscDev's ansrwer (Trên):
LatLng fromLocation = new LatLng(38.5, -100.4); // Whatever origin coordinates
LatLng toLocation = new LatLng(37.7, -107.7); // Whatever destination coordinates
Marker marker = mMap.addMarker(new MarkerOptions().position(firstLocation));
MarkerAnimation.animateMarkerToICS(marker, toLocation, new LatLngInterpolator.Spherical());
Và đối với những ai sử dụng GPS/hoặc bất kỳ nhà cung cấp vị trí đó nhận cập nhật vị trí:
Marker ourGlobalMarker;
// We've got a location from some provider of ours, now we can call:
private void updateMarkerPosition(Location newLocation) {
LatLng newLatLng = new LatLng(newLocation.getLatitude(), newLocation.getLongitude());
if(ourGlobalMarker == null) { // First time adding marker to map
ourGlobalMarker = mMap.addMarker(new MarkerOptions().position(newLatLng));
}
else {
MarkerAnimation.animateMarkerToICS(ourGlobalMarker, newLatLng, new LatLngInterpolator.Spherical());
}
}
QUAN TRỌNG:
Trong vòng 1MarkerAnimation.java
Nếu hoạt ảnh durat ion được đặt thành X, và bạn đang nhận cập nhật vị trí với tốc độ nhỏ hơn X, nhiều hoạt ảnh sẽ chạy và bạn có thể thấy các điểm đánh dấu nhấp nháy.
Để tránh điều này, các phương pháp animationMarkerToICS
(Tôi đã ở đây animationMarkerToICS
ví dụ), nên giống như thế này,
đầy đủ phương pháp thực hiện:
private static Animator animator; // MAKING ANIMATOR GLOBAL INSTEAD OF LOCAL TO THE STATIC FUNCTION
...
// Ice Cream Sandwich compatible
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
public static void animateMarkerToICS(Marker marker, LatLng finalPosition, final LatLngInterpolator latLngInterpolator) {
TypeEvaluator<LatLng> typeEvaluator = new TypeEvaluator<LatLng>() {
@Override
public LatLng evaluate(float fraction, LatLng startValue, LatLng endValue) {
return latLngInterpolator.interpolate(fraction, startValue, endValue);
}
};
Property<Marker, LatLng> property = Property.of(Marker.class, LatLng.class, "position");
// ADD THIS TO STOP ANIMATION IF ALREADY ANIMATING TO AN OBSOLETE LOCATION
if(animator != null && animator.isRunning()) {
animator.cancel();
animator = null;
}
animator = ObjectAnimator.ofObject(marker, property, typeEvaluator, finalPosition);
animator.setDuration((long) ANIMATION_DURATION);
animator.start();
}
Thưởng thức.
Có thể [trùng lặp] (http://stackoverflow.com/questions/13972401/google-map-v2-marker-animation)? Nếu trong giải pháp bạn chọn, bạn sẽ cần phải nội suy các kinh độ, chú ý đến dấu hiệu lật ở kinh tuyến thứ 180. – hleinone
@hleinone không hoàn toàn. Một trong những bạn đã đề cập có giải pháp cho a) di chuyển máy ảnh b) di chuyển một điểm đánh dấu đến một vị trí khác nhau. Tôi cần b) và nó có thể được thực hiện đơn giản chỉ bằng cách thực hiện Marker.setPosition(). Tuy nhiên, việc thay đổi một biểu tượng của điểm đánh dấu (tôi sẽ hiển thị hình ảnh xoay theo hướng chuyển động) không hoạt động. Có vẻ như, người ta cần xóa tất cả các điểm đánh dấu trên bản đồ để thay đổi biểu tượng. –
Để tạo hoạt ảnh cho các tuyến đường polyline https://github.com/amalChandran/google-maps-route-animation – amalBit