Search code examples
ioscocoa-touchmkmapviewmkannotation

How to hide the blue dot and the circle on an MKMapView


Is there a easy way to hide it? I use the user location, but I don't want to show the blue dot. How can I hide it?

-- edit--

Am I using something wrong?

@interface ALMapaViewController : UIViewController <MKMapViewDelegate,
                                                    MKAnnotation>
{
    IBOutlet MKMapView *mapaPrincipal;
    id<ALMapaViewControllerDelegate> delegateMap;
    CLLocationCoordinate2D coordinate; 
}

my .m

@implementation ALMapaViewController

- (void)viewDidLoad{

    [super viewDidLoad];
    [mapaPrincipal setMapType:MKMapTypeStandard];
    [mapaPrincipal setZoomEnabled:YES];
    [mapaPrincipal setScrollEnabled:YES];

    [mapaPrincipal.userLocation addObserver:self 
                                forKeyPath:@"location" 
                                   options:(NSKeyValueObservingOptionNew|NSKeyValueObservingOptionOld) 
                                   context:nil];
    [mapaPrincipal setShowsUserLocation:YES]; 
}


-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {      
    MKCoordinateRegion region;
    region.center = mapaPrincipal.userLocation.coordinate;  
    MKCoordinateSpan span; 
    span.latitudeDelta  = 0.005f; 
    span.longitudeDelta = 0.005f; 
    region.span = span;
    [mapaPrincipal setRegion:region animated:YES];
    self.coordinate = region.center; 
    [mapaPrincipal addAnnotation:self];
    [mapaPrincipal setShowsUserLocation:NO];
}
@end

I already used the showUserLocation and it still show the blue dots.


Solution

  • You want to receive user location updates but not show the blue dot.

    One option is to use CLLocationManager to get updates instead of the map view's showsUserLocation. Call startUpdatingLocation on the location manager and implement its locationManager:didUpdateToLocation:fromLocation: delegate method.

    If you don't want to use CLLocationManager, another option is to hide the user location view that is created by the map view by setting it's hidden property to YES in the map view's didAddAnnotationViews delegate method. The map view will continue to receive user location updates (because you are not setting showsUserLocation to NO) but the blue dot won't show because you're hiding its view.

    An example of the second option is shown in this answer:
    Hide MKUserLocation when MKMapView showsUserLocation == YES


    An unrelated point is that you don't need to use key-value-observing to monitor changes to the map view's userLocation property. Use the mapView:didUpdateUserLocation: delegate method instead.