iPhone:获取 Google 地图的选定缩放级别
当用户使用以下任一方式时,我们需要获取 MKMapView 当前选择的缩放级别 使用 Mapkit 放大或缩小 Google 地图。
我们尝试过的解决方案在模拟器上运行良好,但在真实环境中运行不佳 设备(具有 iOS 3.0.1 的 iPhone 3GS)。我们需要让它在 iOS 3+ 上运行 (包括 iOS 4)
以下是我们用来获取缩放级别的代码:-
在放大/缩小时,Mapkit 调用此委托:-
(void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated
它依次调用我们的 Mapzoomlevel 函数:-
#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)));
}
这段代码取自(请参阅 get缩放级别示例 第一条评论发布于 此博客):-
http://troybrant .net/blog/2010/01/set-the-zoom-level-of-an-mkmapview/
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.
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:-
On zoom-in/out, Mapkit calls this delegate:-
(void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated
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-of-an-mkmapview/
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
https://github.com/jdp-global/MKMapViewZoom
https://github.com/jdp-global/MKMapViewZoom