How to hide the blue dot and the circle on an MKMapView
Asked Answered
G

6

5

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.

Genus answered 2/5, 2012 at 2:56 Comment(0)
N
9

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.

Nepheline answered 2/5, 2012 at 13:17 Comment(0)
A
6

Very simple buddy

[mapView setShowUserLocation:NO];
Argive answered 2/5, 2012 at 3:6 Comment(4)
I used it. But it don't work. What this do is: update or not my current local. This still show the blue dot.Genus
@C4-Travis sorry for delay, but i put it. Look, I already use this property and don't work for this.Genus
@Genus you have set this property to yes that is why it's displaying the blue dot.. [mapaPrincipal setShowsUserLocation:YES]; change this to this [mapaPrincipal setShowsUserLocation:NO];Argive
this is the problem. Ok, if I set to no, it don't show the blue dot, but don't show my place too. I want know my location. Like you see, if I set YES, it show my place, but if I set NO after this, the blue dot don't disappear.Genus
S
0

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;
  }

check this https://mcmap.net/q/1242925/-hide-mkuserlocation-when-mkmapview-showsuserlocation-yes

Smilax answered 8/1, 2016 at 15:54 Comment(0)
L
0

You can use this method

[mapViewSelf setShowsUserLocation:NO];

Lorca answered 16/2, 2017 at 10:0 Comment(0)
F
0

this works fine.

- (void)mapView:(MKMapView *)mapView didAddAnnotationViews (NSArray<MKAnnotationView *> *)views {
  MKAnnotationView *ulv = [mapView viewForAnnotation:mapView.userLocation];
  if (ulv) {
    CALayer *layer = [ulv valueForKeyPath:@"_accuracyLayer"];
    if (layer) {
        [layer removeFromSuperlayer];
    }
  }
}
Forficate answered 1/7, 2020 at 9:3 Comment(0)
C
0

The marked answer is correct, hiding it is very effective. Here's the delegate implemented code the accepted answer was referring to:

   func mapView(_ mapView: MKMapView, didAdd views: [MKAnnotationView]) {
        if let userView = views.first(where: { $0.annotation is MKUserLocation }) {
             userView.isHidden = true
        }
    }
Colonist answered 8/12, 2022 at 4:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.