I need to scroll a MapView programatically to make sure something is in view. I know how many pixels it needs to scroll in each direction. I see methods (in MapController) to animate it to a particular GeoPoint, and to scroll it by pixels without animation. But nothing to do it by pixels, with an animation.
What is an easy way to do this?
Well, since no one answered I'll answer it myself. This seems to work ok:
public static void panMap (int x, int y, MapView map) {
Point ptPixels = new Point();
GeoPoint geoPt = map.getMapCenter();
Projection projection = map.getProjection();
projection.toPixels(geoPt, ptPixels);
ptPixels.x += x;
ptPixels.y += y;
geoPt = projection.fromPixels(ptPixels.x, ptPixels.y);
map.getController().animateTo(geoPt);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With