使用 osmdroid 在 OpenStreet 地图上制作动画标记
Animating markers on OpenStreet Maps using osmdroid
我正在使用给定 here 的 google 地图标记动画逻辑。
我的标记得到动画,但在每个 marker.setPosition(newPosition);
我需要调用 mapView.invalidate();
来刷新地图,导致动画非常缓慢。
有什么解决方法吗?
下一个解决方案对我来说工作正常:
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。
我在此处找到 GoogleMaps v2 实现的来源:
How to animate marker in android map api V2?
我正在使用:
osmdroid-android 5.5 和 osmbonuspack 6.0
我正在使用给定 here 的 google 地图标记动画逻辑。
我的标记得到动画,但在每个 marker.setPosition(newPosition);
我需要调用 mapView.invalidate();
来刷新地图,导致动画非常缓慢。
有什么解决方法吗?
下一个解决方案对我来说工作正常:
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。
我在此处找到 GoogleMaps v2 实现的来源: How to animate marker in android map api V2?
我正在使用: osmdroid-android 5.5 和 osmbonuspack 6.0