Search code examples
androidzoomingregionpan

Is there something similar to 'zoomToRegion' in Android?


I want to zoom in or out of the map depending on where markers on my map are placed. The markers are dynamic so I can not chose a static zoom level. I understand that there is 'zoomToRegion' method in iOS to acheive this. Is there something similar in Android?


Solution

  • Yes. You have to use the method zoomToSpan of MapController.

    // zoom into map to box of results
    int centerLat = (int)(((maxLat-minLat)/2+ minLat)*1E6);
    int centerLon = (int)(((maxLon-minLon)/2 + minLon)*1E6);
    mapView.getController().animateTo(new GeoPoint( centerLat, centerLon));
    mapView.getController().zoomToSpan((int)((maxLat-minLat)*1E6), (int)((maxLon-minLon)*1E6));