ios - iOS:如何知道GMSMapView的缩放级别

标签 ios objective-c google-maps zoom gmsmapview

您好,我想获取Google Map view的当前缩放级别,就像要检查的情况一样。
例如,

if(mapView.zoom==18.0)
{
 //code goes here..
}

如何获得?

最佳答案

您可以使用以下代码。

#define MERCATOR_RADIUS 85445659.44705395
#define MAX_GOOGLE_LEVELS 20

@interface MKMapView (ZoomLevel)
- (double)getZoomLevel;
@end

@implementation MKMapView (ZoomLevel)

- (double)getZoomLevel
{
    CLLocationDegrees longitudeDelta = self.region.span.longitudeDelta;
    CGFloat mapWidthInPixels = self.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;
}

@end

也可以使用MKCoordinateSpan检查document以获取更多信息。
typedef struct {
    CLLocationDegrees latitudeDelta;
    CLLocationDegrees longitudeDelta;
} MKCoordinateSpan;

关于ios - iOS:如何知道GMSMapView的缩放级别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28315604/

相关文章:

ios - Facebook iOS 应用程序用户界面

javascript - 利用 Google Maps API 中的铁路路线

javascript - map 颜色模式 "random"适用于 Google 地球但不适用于 Google map

javascript - Google maps V3 dragend 监听器将所有标记添加回 map

ios - AppDelegate.Swift 上的线程处理

ios - 逐渐提高 SpriteKit 中滚动背景的速度

ios - 无法使用 KVO 在 UIView 动画期间获取新值

ios - 我将如何开始复制 Apple 在 iOS 7 中作为默认设置使用的自定义 View Controller 转换?

iphone - CABasicAnimation CorePlot 缩放效果

ios - 3D Peek and Pop 内存泄漏