this is my fuction in util file. it complains about "Value of type 'UIViewController' has no member 'mapView'"
func removeSpecificCustomAnnotation(annotationArray: [CustomPointAnnotation], annotationIdToRemove: String, viewController: UIViewController) {
for annotation in annotationArray {
if let ID = annotation.locationID, ID == annotationIdToRemove {
viewController.mapView.removeAnnotation(annotation)
}
}
}
i am not allowed to answer anymore. i post my working things here
this is working function. I want to remove a annotation on the map
- in my viewController.swift
- declare var mapView = MKMapView()
- function to display all annotations -> i dont put here
- now, i want to remove one of annotation that displayed above
- i have the ID of annotation (you need to use a custom annotation to do this)
- the ID of annotation is generated by a function based on the latitude and longitude
- now, i need to find the annotation that has that ID and remove it
i get all annotations on the map
let annotations = mapView.annotations.filter { $0 !== self.mapView.userLocation }
loop the annotation arrays and then remove that one i need
for annotation in annotations { let getLat: CLLocationDegrees = annotation.coordinate.latitude let getLon: CLLocationDegrees = annotation.coordinate.longitude let cllocation: CLLocation = CLLocation(latitude: getLat, longitude: getLon) let locationID = Utils.generateLocationID(newcllocation: cllocation, existingCllocationToEdit: nil) if locationID == annotationIdToRemove { self.mapView.removeAnnotation(annotation) } }
UIViewController. - rmaddy