Вы можете использовать делегата "didchange" из googlemaps.
как пример:
func mapView(_ mapView: GMSMapView, didChange position: GMSCameraPosition) {
if mapView.camera.zoom >= 16 {
// ADD YOUR MARKERS HERE
} else {
mapView.clear()
}
}
Если вы хотите добавить анимацию, это работает для меня
func addMarker() {
self.markerArray.removeAll()
for data in yourDataArray {
let iconView = UIImageView.init(frame: CGRect(x: 0, y: 0, width: 0, height: 0))
iconView.image = UIImage(named: "YOUR_IMAGE")
iconView.contentMode = .scaleAspectFit
// Creates a marker in the center of the map.
let marker = GMSMarker()
marker.position = CLLocationCoordinate2D(latitude: data.lat, longitude: data.lng)
marker.iconView = iconView
marker.tracksViewChanges = true
marker.map = mapView
self.markerArray.append(marker)
UIView.animate(withDuration: 0.7,
animations: {
marker.iconView?.frame = CGRect(x: 0, y: 0, width: 29.0, height: 34.0)
}, completion: nil)
}
}
func removeMarker() {
for marker in self.markerArray {
UIView.animate(withDuration: 0.3,
animations: {
marker.iconView?.frame = CGRect(x: 0, y: 0, width: 0, height: 0)
}, completion: nil)
}
self.mapView.clear()
self.markerArray.removeAll()
}