确定mapview的当前缩放比例

时间:2011-05-11 15:23:17

标签: ios zoom android-mapview

如何计算MKMapView的当前zoomScale?

1 个答案:

答案 0 :(得分:0)

使用以下代码:

#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;
}

getZoomLevel方法的返回值将是mapView属性的当前缩放级别。