4

I am trying to add the default button to return to current Location within google map. I added the button using

self.mapView.myLocationButton = YES 

But not able to hide the blue dot which is not required in my case.

If i set

self.mapView.myLocationEnabled = NO

It would remove the functionality to return back to current Location on pressing the current Location button.

Following is the code i've implemented

 - (void)viewDidLoad
 {
     [super viewDidLoad];
     // Do any additional setup after loading the view.

     self.mapView.delegate = self;

     self.mapView.settings.myLocationButton = YES;
     self.mapView.myLocationEnabled = YES;

 }
Arjun K P
  • 2,081
  • 4
  • 20
  • 33

6 Answers6

2

You can simply add the annotation view:

-(void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views
{
    MKAnnotationView *note= [mapView viewForAnnotation:mapView.userLocation];
    note.hidden = YES;
}

In this way the map will still receive user's location updates but the blue dot is hidden. Remember that since this is a delegate method, you should correctly set the delegate.

Antonio E.
  • 4,381
  • 2
  • 25
  • 35
2
  1. self.mapView.myLocationEnabled = NO to hide the blue dot.
  2. set a class to implement CLLocationManagerDelegate to track user's location.
Black.Lee
  • 344
  • 2
  • 7
0

try

    self. mapView.showsUserLocation=NO;
Ahsan
  • 827
  • 6
  • 10
  • 1
    If you set the `showsUserLocation=NO` the Map will stop to track user's location and thus the myLocationButton will be unusable. You can check it in the docs: https://developer.apple.com/library/ios/documentation/MapKit/Reference/MKMapView_Class/MKMapView/MKMapView.html#//apple_ref/occ/instp/MKMapView/showsUserLocation – Antonio E. Apr 29 '14 at 11:13
-1

Easier way would be to replace your annotation with view that has color as clearColor. This way our current location would be shown with an invisible annotation ;-)

Mayur Deshmukh
  • 1,169
  • 10
  • 25
-1

Simply use mapView_.myLocationEnabled = NO;

Its solve your problem

Soumya Ranjan
  • 4,817
  • 2
  • 26
  • 51
-1

In Swift 4x -

mapView.delegate = self
mapView.settings.myLocationButton = true
mapView.isMyLocationEnabled = true
Abhishek Mishra
  • 1,625
  • 16
  • 32