Search code examples
swiftmkannotationviewapple-maps

How to Switch between Clustered and Non Clustered Annotations in Apple Map IOS


So My requirement is pretty straight forward . i Have a switch on map which will allow the users to select the style in which the map annotations should look like

1 . Clustered annotations ( apples default clustering when annotations collide)
2 . Non clustered annotations ( no clustering even if annotations collide)

The method i am using right now is to remove all annotations from map first then add them back . i am using custom annotations for both cluster and normal case

on moving from non clustered to clustered everything works as expected But in reverse case when the clustered icons changed to non clustered some of the annotations are missing from map.

i am setting the clusterIdentifier = nil when i change to non cluster mode and the displayPriority = .required

any suggestions ??


Solution

  • OK . I have made the switching annotation style work by using 2 different identifiers for the 2 view styles and removing and adding all the annotations on Switching.

    so when user opens the app default Identifier is used
    When User Switches the style
    Remove all annotations -> Add all annotations -> Use the identifier for the selected Style

    Now This will work for me. But what i understood from this issue is that the dequeuing annotationView in apple map has some issues when using same annotationview to display differently