iPhone:获取选定的Google地图缩放级别

问题描述:

我们需要获得以下用户的当前选定的MKMapView缩放级别: 使用Mapkit放大或缩小Google Maps.

We need to get the current selected zoom level of MKMapView when user either zooms-in or zooms-out on the Google Maps using Mapkit.

我们尝试过的解决方案在模拟器上运行良好,但在实际环境中却无法运行 设备(具有iOS 3.0.1的iPhone 3GS).我们需要使其在iOS 3+上运行 (包括iOS 4)

The solution we have tried is running fine on simulator but not on real device (iPhone 3GS having iOS 3.0.1). We need to get it running on iOS 3+ (including iOS 4)

以下是我们用于获取缩放级别的代码:-

Following is the code we are using to get the zoom-level:-

在放大/缩小时,Mapkit将此委托称为:-

On zoom-in/out, Mapkit calls this delegate:-

(void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated

依次调用我们的Mapzoomlevel函数:-

which in turns calls our Mapzoomlevel function:-

#define MERCATOR_RADIUS 85445659.44705395

-(float) Mapzoomlevel {
  return 21 - round(log2(_mapView.region.span.longitudeDelta *
    MERCATOR_RADIUS * M_PI / (180.0 * _mapView.bounds.size.width)));
}

此代码摘自(请参阅获取缩放级别示例的第一条评论,发布于 此博客):-

This code was taken from (see get zoom level example first comment posted on this blog):-

http://troybrant.net /blog/2010/01/set-the-zoom-level-an-mkmapview/

https://github.com/jdp-global/MKMapViewZoom

-(void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated{
    int zoomLevel = [mapView zoomLevel];

}