Search code examples
ioscocoa-touchmapkit

Perform action when tapping on My Location in MapKit


Is there a way to trigger code to execute when tapping on the "My Location" blue dot in MapKit?

enter image description here

I tried implementing func mapView(_ mapView: MKMapView, didDeselect view: MKAnnotationView) { but this doesn't get called when tapping the blue dot. Instead, a pretty useless generic avatar annotation shows up as shown in the simulator screenshot above. Can this behavior be customized?


Solution

  • You need to implement the delegate function mapView(viewForAnnotation) and substitute your own view in the case where the annotation is the MKUserLocation. Now you are in charge of how the caption behaves.