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?
Is it possible to force MapKit to show all annotations without clustering?
Asked Answered
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
}
}
}
}
I have posted a question here. could you please take a look? thank you –
Zephan
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
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.
This should be the accepted answer. You solved my problem! –
Hardly
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
}
}
}
}
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 you –
Zephan
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.
clusteringIdentifier
to nil but still markers disappear when zoomed out. – Zephan