MapKit: Selecting and deselecting annotation

Hi there, I am using MapKit for my tvOS app

I got a problem and I don't know how to solve it

Here is the problem:

I had lots of annotations on my mapView, I selected one of them by using siri remote and it changed annotation view and showed up custom callout view

but I don't know how to deselect the annotation which was selected...


I had tried

    open func deselectAnnotation(_ annotation: MKAnnotation?, animated: Bool)

but MapKit will find next annotation to select immediately! and the property "selectedAnnotations: [MKAnnotation]" always has item!

so I cant deselect

Is there any solution for this?

many thanks!

This question is nearly two years old.


Can someone please assist, and make me aware of the following. If I have say three annotations on a map, i click the siri remote Play button and can pan to each of the markers, which will select each. Though, how can I deselect an annotation, or alternately all annotations on the map?


I tried long press gesturerecognizer on each annotation view, though these do not appear to trigger.


Thanks.

This will deselect all annotations, which have been previously selected.
Code Block
let selectedAnnotations = mapView.selectedAnnotations
for annotation in selectedAnnotations {
      mapView.deselectAnnotation(annotation, animated: false) // better to animate selection, since deselection could be many
}


MapKit: Selecting and deselecting annotation
 
 
Q