Radius of the mapview
I have a mapview when the user click on the mapview it set the lon & the lat points. I want to be able to capture the zoom level / radius in distance of the zoom what is the best开发者_JS百科 way to do this?
Please check this question: Android: How do I set the zoom level of map view to 1 km radius around my current location?
Worked fine for me.
You have to use:
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
mapView.getController().setZoom(calculateZoomLevel(metrics.widthPixels));
private int calculateZoomLevel(int screenWidth) {
double equatorLength = 40075004; // in meters
double widthInPixels = screenWidth;
double metersPerPixel = equatorLength / 256;
int zoomLevel = 1;
while ((metersPerPixel * widthInPixels) > 1000) {
metersPerPixel /= 2;
++zoomLevel;
}
return zoomLevel;
}
getZoomLevel()
is the method you are looking for.
精彩评论