gpt4 book ai didi

ios8 - 如何在IOS SDK 8.0中获取当前位置的经纬度

转载 作者:行者123 更新时间:2023-12-04 07:37:26 25 4
gpt4 key购买 nike

如何获取当前位置的经纬度。

我试过这个。使用 Xcode 6.01 和 IOS SDK 8.0

-(CLLocationCoordinate2D) getLocation{
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
locationManager.distanceFilter = kCLDistanceFilterNone;
[locationManager startUpdatingLocation];
CLLocation *location = [locationManager location];
CLLocationCoordinate2D coordinate = [location coordinate];
return coordinate;
}

- (void)getCurrentLocation{
CLLocationCoordinate2D coordinate = [self getLocation];
NSString *latitude = [NSString stringWithFormat:@"%f", coordinate.latitude];
NSString *longitude = [NSString stringWithFormat:@"%f", coordinate.longitude];
NSLog(@"Latitude = %@", latitude);
NSLog(@"Longitude = %@", longitude);
}


- (void)viewDidLoad{
[super viewDidLoad];
[self getCurrentLocation];

}

在这里,我将模拟器位置启用为 Deployment 8.0 iPhone 模拟器 4s。
即使在设备上也无法正常工作。

@全部
请让我知道,我在这里做错了什么。

最佳答案

我在 IOS 8.0 中解决了问题

NSLocationAlwaysUsageDescription 将此手动添加到应用程序 plist 文件中,将字符串值留空。
这将调用委托(delegate)方法。永远不要忘记添加 NSLocationAlwaysUsageDescription 除非您没有添加此委托(delegate)方法,否则将不起作用。其余代码相同。向 Controller 类添加委托(delegate)方法。

在 locationManager 声明代码中添加这行代码。 IOS 8.0
[locationManager requestAlwaysAuthorization];

关于ios8 - 如何在IOS SDK 8.0中获取当前位置的经纬度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26147984/

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