开发者

Radius of the mapview

开发者 https://www.devze.com 2023-03-23 13:08 出处:网络
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

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消