本文介绍了iPhone:获取选定的Google地图缩放级别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

We need to get the current selected zoom level of MKMapView when user eitherzooms-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 realdevice (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 onthis 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];

}

这篇关于iPhone:获取选定的Google地图缩放级别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 07:19