gpt4 book ai didi

ios - 对于 google maps iOS sdk,当前位置偶尔会绘制在 0,0

转载 作者:行者123 更新时间:2023-11-28 19:46:50 25 4
gpt4 key购买 nike

不确定为什么会发生这种情况,但当发生这种情况时,我们不希望向用户显示他们的当前位置是 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];
}

这将使用当前位置不断更新 map 。如果您只想当前位置一次,只需为其添加一个条件语句即可。

如果用户拒绝权限,将调用以下方法:

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

关于ios - 对于 google maps iOS sdk,当前位置偶尔会绘制在 0,0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31682999/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com