Search code examples
iosswiftannotationsmapkitcallout

How to show all annotations call out Swift


I have an app which has a lot of annotations and I want to have their call outs open at the beginning(and if its possible never disappear). What I accomplished since now is to have only one always appeared and when I tap the map it disappears with this line:

 mapView.selectAnnotation(mapView.annotations[1], animated: true)

Thanks in advance.


Solution

  • I just did some research and I found that it's not possible from public API and MKMapView mechanisms.

    The code below just select an annotation and in the same time deselect the previous one.

    for annotation in mapView.annotations {
         mapView.selectAnnotation(annotation, animated: true)
    }
    

    So to provide the behavior you've described you have to implement some custom mechanism.

    Also, you might look to this answer. It would be very helpful.