Home > Software engineering >  Swift mapkit how to hide user's location pin
Swift mapkit how to hide user's location pin

Time:10-20

I could not find any documentation on that so maybe it is not possible I am asking anyway. I need to show the blue dot for user location. My mapview is filled with pins and sometimes my user are clicking on the blue circle of the user location which opens a small user picture pin. How can I remove that? It's annoying if something is behind.

user location pin

So far, I got to identify when I open the annotationview like that :

func mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView) {
    if(view.annotation?.isKind(of: MKUserLocation.self) != true){
        print("test");
    }
}

Is there a way to cancel it from showing?

CodePudding user response:

You have 99% of the solution - You have identified when the user location annotation is selected. All you need to do to complete your task is deselect it;

func mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView) {
        
    if view.annotation is MKUserLocation {
        mapView.deselectAnnotation(view.annotation, animated: false)
        return
    }

    // Handle selection of other annotations if required...
}

CodePudding user response:

Im 99% sure that is not possible. Unless it has something to do with MKAnnotationView, I would recommend using google places sdk.

  • Related