With official Google Maps iOS SDK documentation:
- (BOOL) myLocationEnabled [read, write, assign] Controls whether the My Location and Precision points are enabled.
The default is NO.
- (CLLocation *) myLocation [read, assign] If My Location is enabled, displays where the user's location point is displayed.
If it is disabled or enabled, but location data is not available, it will be nil. This property can be observed using KVO.
Therefore, when you set mapView_.myLocationEnabled = YES; , it tells mapView to show the blue dot only if you have the location value assigned to the myLocation property. A sample code from Google shows how to monitor a user's location using the KVO method. (Recommended) You can also implement the CLLocationManagerDelegate method to update mapView.
-(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation { [mapView animateToLocation:newLocation.coordinate];
Here is the code from the Google Maps sample code that describes how to use KVO to update the user's location.
// in viewDidLoad method... // Listen to the myLocation property of GMSMapView. [mapView_ addObserver:self forKeyPath:@"myLocation" options:NSKeyValueObservingOptionNew context:NULL]; // Ask for My Location data after the map has already been added to the UI. dispatch_async(dispatch_get_main_queue(), ^{ mapView_.myLocationEnabled = YES; }); - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { if (!firstLocationUpdate_) { // If the first location update has not yet been recieved, then jump to that // location. firstLocationUpdate_ = YES; CLLocation *location = [change objectForKey:NSKeyValueChangeNewKey]; mapView_.camera = [GMSCameraPosition cameraWithTarget:location.coordinate zoom:14]; } }
source share