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

2

5

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?

Preheat answered 27/1, 2018 at 6:26 Comment(0)
S
3

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
            }
        }
    }
}
Steelyard answered 27/1, 2018 at 14:1 Comment(3)
I've set the clusteringIdentifier to nil but still markers disappear when zoomed out.Zephan
I have posted a question here. could you please take a look? thank youZephan
This seems to work if you subclass MKPinAnnotationView but not MKMarkerAnnotationView. Is there anyway to disable clustering without losing the functionality of the markerview?Viewer
E
8

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.

Extrabold answered 18/11, 2018 at 22:27 Comment(1)
This should be the accepted answer. You solved my problem!Hardly
S
3

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
            }
        }
    }
}
Steelyard answered 27/1, 2018 at 14:1 Comment(3)
I've set the clusteringIdentifier to nil but still markers disappear when zoomed out.Zephan
I have posted a question here. could you please take a look? thank youZephan
This seems to work if you subclass MKPinAnnotationView but not MKMarkerAnnotationView. Is there anyway to disable clustering without losing the functionality of the markerview?Viewer

© 2022 - 2024 — McMap. All rights reserved.