开发者

determine current zoomscale for mapview

开发者 https://www.devze.com 2023-03-04 23:17 出处:网络
How can I calculate the current zoomScale for an MKM开发者_运维技巧apView?Use the following code:

How can I calculate the current zoomScale for an MKM开发者_运维技巧apView?


Use the following code:

#define MERCATOR_RADIUS 85445659.44705395
#define MAX_GOOGLE_LEVELS 20

- (double)getZoomLevel {
    CLLocationDegrees longitudeDelta = self.mapView.region.span.longitudeDelta;
    CGFloat mapWidthInPixels = self.mapView.bounds.size.width;
    double zoomScale = longitudeDelta * MERCATOR_RADIUS * M_PI / (180.0 * mapWidthInPixels);
    double zoomer = MAX_GOOGLE_LEVELS - log2( zoomScale );
    if ( zoomer < 0 ) zoomer = 0;
    //  zoomer = round(zoomer);
    return zoomer;
}

The return value of the getZoomLevel method will be the current zoom level of your mapView property.

0

精彩评论

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

关注公众号