Last active
April 13, 2023 08:19
-
-
Save minikin/46f5599b5d46445c4c59 to your computer and use it in GitHub Desktop.
Remove all annotation from mapView [MapBox]
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// Remove all annotation from mapView (MapBox) | |
func removeAllAnnotations() { | |
guard let annotations = mapView.annotations else { return print("Annotations Error") } | |
if annotations.count != 0 { | |
for annotation in annotations { | |
mapView.removeAnnotation(annotation) | |
} | |
} else { | |
return | |
} | |
} |
[self.mapContainer removeAnnotations:self.mapContainer.annotations]; in Objective C
in Swift will be similar
if let annotations = mapView.annotations {
mapView.removeAnnotations(annotations)
}
SWIFT 5 and Xcode 14.3 Target iOS 16.1
@IBOutlet var mapViewX: MKMapView!// Outlet.
// Clean all map annotations.
for annotationX in mapViewX.annotations
{
mapViewX.removeAnnotation(annotationX)
}
// Delete specific annotation.
for annotationX in mapViewX.annotations
{
if annotationX.title == "Your title"
{
mapViewX.removeAnnotation(annotationX)
}
}
// Clean route lines.
for overlayX in mapViewX.overlays
{
mapViewX.removeOverlay(overlayX)
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
its no removing my annotations