不要删除我地图上的所有注释

时间:2016-04-15 07:44:41

标签: ios swift annotations mapkit mapkitannotation

我有这个按钮,应该显示/隐藏地图上的某些注释引脚。我在下面有这个功能,但是当你按下它来移除引脚时,它会移除所有引脚。它应该只删除addAttractionPinsBilka中的引脚?我该怎么做才能实现这一目标?

这是我的代码:

@IBAction func bilkaAction(sender: AnyObject) {
    if !annotationBilkaIsVisible {
        addAttractionPinsBilka()
        annotationBilkaIsVisible = true

    }else {
        map.removeAnnotations(map.annotations)
        annotationBilkaIsVisible = false
    }
}

希望你能帮助我: - )

1 个答案:

答案 0 :(得分:0)

假设您在addAttractionPinsBilka()中添加的注释类型为Artwork

以下代码删除该类型的所有注释

for annotation in map.annotations where annotation is Artwork {
    map.removeAnnotation(annotation)
}