我这里有一张 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/