【问题标题】:Is it possible to force MapKit to show all annotations without clustering?是否可以强制 MapKit 显示所有注释而不进行聚类?
【发布时间】:2018-01-27 06:26:46
【问题描述】:

我有两个类都符合MKAnnotation,我想知道,当用户缩小并显示所有注释时,有没有办法强制MapKit 不聚集注释?

【问题讨论】:

    标签: ios swift mapkit mkannotation


    【解决方案1】:

    上述解决方案对我不起作用,但此解决方案有效

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

    希望对你有帮助。

    【讨论】:

    • 这应该是公认的答案。你解决了我的问题!
    【解决方案2】:

    将 MKAnnotation 的 clusteringIdentifier 设置为 nil。

    例如

    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
                }
            }
        }
    }
    

    【讨论】:

    • 我已将 clusteringIdentifier 设置为 nil,但缩小时标记仍然消失。
    • 我已经发布了一个问题here。你能看看吗?谢谢
    • 如果您继承 MKPinAnnotationView 而不是 MKMarkerAnnotationView,这似乎有效。有没有办法在不丢失markerview功能的情况下禁用聚类?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多