如何使用 MapKit 从地图中删除所有注释
How can I remove all annotations from a map using MapKit
我尝试过使用 RemoveAnnotation 函数,但我不知道如何将它们全部删除
struct MapView: View {
@State private var region = MKCoordinateRegion(
center: CLLocationCoordinate2D(
latitude: 25.7617,
longitude: 80.1918
),
span: MKCoordinateSpan(
latitudeDelta: 100,
longitudeDelta: 100
)
)
var body: some View {
Map(coordinateRegion: $region)
} }
我正在使用这个扩展程序
extension MKMapView {
func removeAnnotationAndOverlay(annotation: MKAnnotation) {
removeAnnotation(annotation)
if overlays.count > 0 {
if let overlay = overlays.first {
removeOverlay(overlay)
}
}
}
func removeAllOverlays() {
removeOverlays(overlays)
}
func removeAllAnnotations() {
removeAnnotations(annotations)
}
func removeAllAnnotationsAndOverlays() {
removeAllOverlays()
removeAllAnnotations()
}
}
我尝试过使用 RemoveAnnotation 函数,但我不知道如何将它们全部删除
struct MapView: View {
@State private var region = MKCoordinateRegion(
center: CLLocationCoordinate2D(
latitude: 25.7617,
longitude: 80.1918
),
span: MKCoordinateSpan(
latitudeDelta: 100,
longitudeDelta: 100
)
)
var body: some View {
Map(coordinateRegion: $region)
} }
我正在使用这个扩展程序
extension MKMapView {
func removeAnnotationAndOverlay(annotation: MKAnnotation) {
removeAnnotation(annotation)
if overlays.count > 0 {
if let overlay = overlays.first {
removeOverlay(overlay)
}
}
}
func removeAllOverlays() {
removeOverlays(overlays)
}
func removeAllAnnotations() {
removeAnnotations(annotations)
}
func removeAllAnnotationsAndOverlays() {
removeAllOverlays()
removeAllAnnotations()
}
}