如何在特定的相机变焦下隐藏和显示我的自定义标记?
例如,如果我的相机变焦超过13,则隐藏所有自定义标记;如果低于13,则显示标记。
var locationManager = CLLocationManager()
override func viewDidLoad() {
super.viewDidLoad()
let camera = GMSCameraPosition.camera(withLatitude: (locationManager.location?.coordinate.latitude)!, longitude: (locationManager.location?.coordinate.longitude)!, zoom: 15)
// Map initiation code
let mapView = GMSMapView.map(withFrame: CGRect.zero, camera: camera)
view = mapView
mapView.mapType = .normal
mapView.isMyLocationEnabled = true
mapView.settings.myLocationButton = true
mapView.settings.compassButton = true
mapView.setMinZoom(6, maxZoom: 19)
// Creates a marker in the center of the map.
let marker = GMSMarker()
marker.icon = self.imageWithImage(image: UIImage(named: "marker_64")!, scaledToSize: CGSize(width: 24.0, height: 24.0))
marker.position = CLLocationCoordinate2D(latitude: 25.034265, longitude: 121.564537)
marker.title = "Taipei 101"
marker.snippet = "101"
marker.map = mapView
marker.tracksViewChanges = true
}
func imageWithImage(image:UIImage, scaledToSize newSize:CGSize) -> UIImage{
UIGraphicsBeginImageContextWithOptions(newSize, false, 0.0)
image.draw(in: CGRect(x: 0, y: 0, width: newSize.width, height: newSize.height))
let newImage:UIImage = UIGraphicsGetImageFromCurrentImageContext()!
UIGraphicsEndImageContext()
return newImage
}