Hide MKUserLocation when MKMapView showsUserLocation == YES
Asked Answered
R

2

8

After setting mapView.showsUserLocation to true, is it possible to receive location updates without showing the MKUserLocation bubble? Returning nil in mapView:viewForAnnotation: simply shows the bubble, and returning any other kind of annotation shows an annotation, which I don't want.

Rafael answered 14/3, 2012 at 23:25 Comment(0)
S
26

You can hide the user location's view in the didAddAnnotationViews delegate method:

-(void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views
{
    MKAnnotationView *ulv = [mapView viewForAnnotation:mapView.userLocation];
    ulv.hidden = YES;
}
Sedentary answered 15/3, 2012 at 2:12 Comment(4)
Wow, perfect. I didn't realize you could manipulate MKAnnotationViews this way. Though I suppose it makes sense, as they are just UI objects. Thank you!Rafael
@Elgert, This method should be in the class that implements the MKMapView delegate (usually the one that contains the map view). Make sure the map view's delegate property is set.Sedentary
i did what you said and still the blue marker appears :(Varga
@Elgert, Please ask a new question with details and the code you are using.Sedentary
M
3

Swift 3:

func mapView(_ mapView: MKMapView, didAdd views: [MKAnnotationView]) {
   if let userLocation = mapView.view(for: mapView.userLocation) {
        userLocation.isHidden = true
   }
}
Melvinmelvina answered 19/1, 2017 at 10:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.