Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 512
dinosaysrawr Avatar asked Jan 02 '23 21:01

dinosaysrawr


2 Answers

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.

like image 146
Tung Fam Avatar answered Jan 05 '23 16:01

Tung Fam


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
            }
        }
    }
}
like image 43
Kosuke Ogawa Avatar answered Jan 05 '23 15:01

Kosuke Ogawa