Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

animate scroll of mapview (by pixels, not lat long)

Tags:

android

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?

like image 948
rob Avatar asked Jan 25 '26 05:01

rob


1 Answers

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);
}
like image 115
rob Avatar answered Jan 27 '26 19:01

rob



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!