对于谷歌地图的iOS SDK,当前的位置偶尔得到绘制在0,0

不知道为什么会发生这种情况,但是如果发生这种情况,我们不希望向用户显示他们当前的位置是0,0(位于南非海岸的中间)。 有什么办法来检测这种情况何时发生,以便我们可以向用户显示错误信息或其他信息?

看起来你没有权限访问设备的当前位置。 为此,您必须将这两个键添加到您的plist中:

NSLocationAlwaysUsageDescription NSLocationWhenInUseUsageDescription 

现在,当你完成它,你将不得不要求这样的授权:

 if ([locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) { [locationManager requestWhenInUseAuthorization]; } 

所以现在,当你完成授权时,你需要开始获取位置更新。 为此,请使用以下行:

 [locationManager startUpdatingLocation]; 

现在如果你想要去当前的位置,你需要在这里实现这个方法:

  - (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations{ CLLocation *location = [locations lastObject]; GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:location.coordinate.latitude longitude:location.coordinate.longitude zoom:currentZoom]; [self.gMapView animateToCameraPosition:camera]; } 

这将不断更新当前位置的地图。 如果你只想要当前位置一次,只要把相同的条件陈述。

如果用户拒绝该权限,则会调用以下方法:

 - (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error{ if([CLLocationManager locationServicesEnabled]) { if([CLLocationManager authorizationStatus] == kCLAuthorizationStatusDenied) { // Put your alert here. } } }