is it possible to delete all observers and kept one( on user current location)
because my app keep cloning my custom annotation non-stop
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
let locValue:CLLocationCoordinate2D = manager.location!.coordinate
map.mapType = MKMapType.standard
let span = MKCoordinateSpan(latitudeDelta: 0.005, longitudeDelta: 0.005)
let region = MKCoordinateRegion(center: locValue, span: span)
map.setRegion(region, animated: true)
let annotation = MKPointAnnotation()
annotation.coordinate = locValue
annotation.title = "Yo"
annotation.subtitle = "current location"
map.addAnnotation(annotation)
self.latitud.text = String(manager.location!.coordinate.latitude)
self.longitud.text = String(manager.location!.coordinate.longitude)
UserDefaults.standard.set(latitud.text, forKey: "latitudeConductor")
UserDefaults.standard.set(longitud.text, forKey: "longitudConductor")
}
// func for custom annotation
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
if annotation is MKUserLocation{
return nil
}
let annotationView = MKAnnotationView(annotation: annotation, reuseIdentifier: "customannotation")
annotationView.image = UIImage(named: "Puntero_carrito.2-2")
annotationView.canShowCallout = true
return annotationView
}