Is it possible to force MapKit to show all annotations without clustering?

╄→гoц情女王★ 提交于 2019-12-11 02:19:36

问题


I have two classes that both conform to MKAnnotation, and I was wondering, is there a way to force MapKit to not cluster the annotation when a user zooms out and display all annotations?


回答1:


Set MKAnnotation's clusteringIdentifier to nil.

e.g.

class BikeView: MKMarkerAnnotationView {

    override init(annotation: MKAnnotation?, reuseIdentifier: String?) {
        super.init(annotation: annotation, reuseIdentifier: reuseIdentifier)
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    override var annotation: MKAnnotation? {
        willSet {
            if let bike = newValue as? Bike {
                clusteringIdentifier = nil
            }
        }
    }
}



回答2:


The mentioned solution didn't work for me, but this solution worked:

final class CarPinMarkerView: MKMarkerAnnotationView {
  override var annotation: MKAnnotation? {
    willSet {
        displayPriority = MKFeatureDisplayPriority.required
    }
  }
}

Hope it helps.



来源:https://stackoverflow.com/questions/48685469/disabling-mkmapview-clustering-annotations-automatically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!