删除所有注释的方法如下,但我需要删除特定的注释
self.mapView.annotations.forEach {
if !($0 is MKUserLocation) {
self.mapView.removeAnnotation($0)
}
}
或
func removeAllAnnotations() {
let annotations = mapView.annotations.filter {
$0 !== self.mapView.userLocation
}
mapView.removeAnnotations(annotations)
}
我试图在两天前搜索但没有帮助,有人可以告诉我。抱歉打扰你
注释数组如下
array = [{annotationID: 1234, anotationTitle: "myLocation"},
{annotationID: 321, anotationTitle: "locationMy"}]
我想删除
{annotationID: 1234, anotationTitle: "myLocation"}
怎么可能?
答案 0 :(得分:1)
有一些方法可以做到这一点。如果您可以识别标题,请尝试以下代码。
func removeSpecificAnnotation() {
for annotation in self.mapView.annotations {
if let title = annotation.title, title == "myLocation" {
self.mapView.removeAnnotation(annotation)
}
}
}