【问题标题】:Do not remove all annotations on my map不要删除我地图上的所有注释
【发布时间】:2016-04-15 07:44:40
【问题描述】:

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

这是我的代码:

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

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

希望你能帮助我:-)

【问题讨论】:

  • 下面的代码去掉所有的注解:map.removeAnnotations(map.annotations)addAttractionPinsBilka()里面加了什么样的注解?您必须只删除这种类型的注释。
  • @AndreasBauer 其中很多都在 addAttractionPinsBilka() 中:let bilka1 = Artwork(title: "Bilka, Hillerød", locationName: "Tryk for rute", discipline: "Butik", coordinate: CLLocationCoordinate2D(latitude: 55.931326, longitude: 12.284186))
  • 好的,注释的类型是Artwork。请看下面我的回答。希望对您有所帮助。

标签: ios swift annotations mapkit mapkitannotation


【解决方案1】:

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

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-03-02
    • 1970-01-01
    • 2023-03-15
    • 2017-07-31
    • 2016-05-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多