使用osmdroid在OpenStreet地图上制作动画标记 [英] Animating markers on OpenStreet Maps using osmdroid
问题描述
我正在使用此处给出的Google Maps标记动画逻辑.
I'm using the google Maps marker animation logic given here.
我的标记被激活,但是在每个marker.setPosition(newPosition);
之后
我需要调用mapView.invalidate();
来刷新地图,从而导致动画速度很慢.
My marker gets animated,but after each marker.setPosition(newPosition);
I need to call mapView.invalidate();
which refreshes the map resulting in very sluggish animation.
有什么解决方法吗?
推荐答案
下一个解决方案对我来说是正确的:
The next solution is working correctly for me:
import org.osmdroid.api.IGeoPoint;
import org.osmdroid.api.IMapController;
import org.osmdroid.util.GeoPoint;
import org.osmdroid.views.MapView;
import org.osmdroid.views.Projection;
import org.osmdroid.views.overlay.Marker;
public void animateMarker(final Marker marker, final GeoPoint toPosition) {
final Handler handler = new Handler();
final long start = SystemClock.uptimeMillis();
Projection proj = map.getProjection();
Point startPoint = proj.toPixels(marker.getPosition(), null);
final IGeoPoint startGeoPoint = proj.fromPixels(startPoint.x, startPoint.y);
final long duration = 500;
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.getLongitude() + (1 - t) * startGeoPoint.getLongitude();
double lat = t * toPosition.getLatitude() + (1 - t) * startGeoPoint.getLatitude();
marker.setPosition(new GeoPoint(lat, lng));
if (t < 1.0) {
handler.postDelayed(this, 15);
}
map.postInvalidate();
}
});
}
它基于某些人对GoogleMaps v2所做的相同实现,但适用于osmdroid.
It is based on the same implementation done by some people for GoogleMaps v2, but adapted to osmdroid.
我在这里找到GoogleMaps v2的实现的来源: 如何在android map api V2中对标记进行动画处理?
The source where I found the implementation for GoogleMaps v2 is here: How to animate marker in android map api V2?
我正在使用: osmdroid-android 5.5和osmbonuspack 6.0
I am using: osmdroid-android 5.5 and osmbonuspack 6.0
这篇关于使用osmdroid在OpenStreet地图上制作动画标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!