iOS9 更新:我是 iOS 新手,正在尝试使用 CoreLocation 来返回纬度和经度值。以下代码从不执行日志输出
-(void)viewWillAppearBOOL)animated{
manager = [[CLLocationManager alloc]init];
manager.delegate = self;
manager.desiredAccuracy = kCLLocationAccuracyBest;
[manager startUpdatingLocation];
}
这是我的 didUpdateToLocation 函数,但从未达到
- (void)locationManagerCLLocationManager *)manager
didUpdateLocationsNSArray<CLLocation *> *)locations{
NSLog(@"Location: %@", locations);
CLLocation *currentLocation = locations.lastObject;
if (currentLocation != nil) {
float latitude = currentLocation.coordinate.latitude;
float longitude = currentLocation.coordinate.longitude;
NSLog(@"dLongitude : %f", longitude);
NSLog(@"dLatitude : %f", latitude);
}
else{ NSLog(@"ERROR");
}
}
CLLocationManager
是异步的,你应该在委托(delegate)方法中获取经纬度。
locationManager.delegate = self;
然后实现这个委托(delegate)方法:
- locationManager:didUpdateLocations:
关于ios - 未检索到纬度和经度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34192331/
欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) | Powered by Discuz! X3.4 |