ios - 为 Google Maps iOS 应用缩放级别条件

标签 ios swift

我这里有一张 map :

let camera = GMSCameraPosition.cameraWithLatitude(37.0902, longitude: -95.7129, zoom: 4.0)

        let mapView = GMSMapView.mapWithFrame(CGRect.zero, camera: camera)
        mapView.myLocationEnabled = true
        view = mapView
        mapView.setMinZoom(4.6, maxZoom: 8)

我想检测用户的缩放级别。如果缩放级别大于 5,则添加标记。怎么做到的?

这是添加标记的代码:

let state_marker = GMSMarker()
            state_marker.position = CLLocationCoordinate2D(latitude: -152.404419, longitude: 61.370716)
            state_marker.title = "Test"
            state_marker.snippet = "Hey, this is Test"
            state_marker.map = mapView

最佳答案

您可以使用 didChangeCameraPosition 委托(delegate) GMSMapView 的方法

首先,您需要在您的类中扩展您的GMSMapView 委托(delegate)

class MyViewController: GMSMapViewDelegate

然后你需要在声明 mapView 之后分配你的委托(delegate)

let camera = GMSCameraPosition.cameraWithLatitude(37.0902, longitude: -95.7129, zoom: 4.0)

let mapView = GMSMapView.mapWithFrame(CGRect.zero, camera: camera)
mapView.myLocationEnabled = true
mapView.delegate = self
view = mapView
mapView.setMinZoom(4.6, maxZoom: 8)

然后您可以使用 didChangeCameraPosition 委托(delegate)方法

func mapView(mapView: GMSMapView!, didChangeCameraPosition position: GMSCameraPosition!) { 
    if(mapView.camera.zoom > 5)
      //do your code here
    }
}

您可以引用以下链接以更好地了解 GMSMapView 的委托(delegate)方法 https://developers.google.com/maps/documentation/ios-sdk/reference/protocol_g_m_s_map_view_delegate-p

关于ios - 为 Google Maps iOS 应用缩放级别条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39806320/

相关文章:

ios - 显示 ViewControllerB 并关闭 ViewControllerA

ios - 在 IOS 上从 S3 存储桶下载时出错。

ios - 如何在不同的 UICollectionView 单元格中显示不同的视频?

ios - 在 XCode 6 beta 7 中从 Swift 在 iOS 中打印

ios - UIDocumentInteractionController 操作/选项菜单在首次启动时不可见

ios - swift ios 在上传前减小图像大小

jquery - 修复 iOS 视口(viewport)以防止 'drag' 效果

ios - 如何同时使用 swift 2 和 swift 3?

ios - didSelectRowAtIndexPath 之后的延迟

ios - 通过触摸来回移动物体