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?

有帮助吗?

解决方案

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));
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top