不能使用CLLocation Manager在iOS 8中获取用户的位置? [英] Not able to get the user's location in iOS 8 using CLLocation Manager?
本文介绍了不能使用CLLocation Manager在iOS 8中获取用户的位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图得到用户的纬度和经度,但是我得到了结果0.000000 - 我已经尝试了以下代码。
I tried to get the user's latitude and longitude but I got result 0.000000 - I have tried following code.
- 我分配了位置管理器变量。
- 位置管理器分配并设置代理是自我
- 检查iOS 8版本验证请求。
- 使用位置启动更新位置功能。</ li>
- I have assign the location manager variable.
- Location Manager allocated and set the delegate is self.
- Checked the iOS 8 version validation requesting.
- Using location start update location function.
代码:
locationmanager=[[CLLocationManager alloc]init];
locationmanager.delegate=self;
// check before requesting, otherwise it might crash in older version
if ([locationmanager respondsToSelector:@selector(requestWhenInUseAuthorization)]) {
[locationmanager requestWhenInUseAuthorization];
}
[locationmanager startUpdatingLocation];
#pragma mark - CLLocationManagerDelegate
-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
NSLog(@"locations %@",locations);
CLLocation*location = [locations lastObject];
NSLog(@"location %f",location.coordinate.latitude);
}
结果:2014-10-15 11: 10:20.118好[714:25676]纬度0.000000
Result:2014-10-15 11:10:20.118 Good[714:25676] latitude 0.000000
推荐答案
确保你已经添加以下行NSLocationWhenInUseUsageDescription或.plist文件中的NSLocationAlwaysUsageDescription。
Make sure that you have added the following lines NSLocationWhenInUseUsageDescription or NSLocationAlwaysUsageDescription in .plist file.
这篇关于不能使用CLLocation Manager在iOS 8中获取用户的位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文