lacas
lacas

Reputation: 14077

Android How to get my MapView's Screen coord? (the visible rect)

How can I get the my MapView's Screen coord to save? (visible rect left-top, and zoomlevel) I'd like to reload that coords after a while. How can I do that?

Thanks, Leslie

Upvotes: 3

Views: 1249

Answers (2)

Dmitriy Tarasov
Dmitriy Tarasov

Reputation: 1969

You needn't know coordinates of visible area (corners of your MapView). The center of the screen and a zoom level will be enough.

// obtain and persist this values
GeoPoint center = mapView.getMapCenter();
int zoomLevel = mapView.getZoomLevel();

// later restore them when you need 
GeoPoint center = ...;
int zoomLevel = ...;

// and init your MapView with this values
MapController controller = mapView.getController();
controller.setZoom(zoomLevel);
controller.animateTo(center);

Upvotes: 0

Rosen Martev
Rosen Martev

Reputation: 519

I don't know if you have found an answer to your question, so I'll show you my solution. I've put the following code a subclass of the class MapView.

    GeoPoint topLeft = this.getProjection().fromPixels(getLeft(), getTop());
    GeoPoint bottomRight = this.getProjection().fromPixels(getRight(), getBottom());
    int topLat = topLeft.getLatitudeE6();
    int topLng = topLeft.getLongitudeE6();
    int bottomLat = bottomRight.getLatitudeE6();
    int bottomLng = bottomRight.getLongitudeE6();

I hope it will help you.

Upvotes: 6

Related Questions