获取核心位置时出错:(null)

时间:2013-07-02 13:04:01

标签: iphone ios objective-c core-location cllocationmanager

我无法在设备上获取当前位置。它首先显示正确,但第三次失败并显示此消息:

Error while getting core location : (null)

我的代码是:

CLLocationManager *manager;
manager = [[CLLocationManager alloc] init];
    manager.pausesLocationUpdatesAutomatically=NO;
    manager.delegate = self;//or whatever class you have for managing location
    [manager startUpdatingLocation];

- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
    NSLog(@"in update location");
}

- (void)locationManager:(CLLocationManager *)manager
       didFailWithError:(NSError *)error
{
    NSLog(@"Error while getting core location : %@",[error localizedFailureReason]);
}

输出是:

2013-07-03 18:32:33.146 CLLocationUpdate[6084:907] in update location
2013-07-03 18:32:33.200 CLLocationUpdate[6084:907] in update location
2013-07-03 18:32:33.517 CLLocationUpdate[6084:907] in update location
2013-07-03 18:32:34.073 CLLocationUpdate[6084:907] in update location
2013-07-03 18:32:50.903 CLLocationUpdate[6084:907] Error while getting core location : (null)

请帮助。 提前谢谢。

3 个答案:

答案 0 :(得分:0)

那种错误(操作无法完成。(kCLErrorDomain错误0.))可能是由于很多原因造成的。

我找到了几个谈论这个问题的链接,你检查过它们吗?

Location Manager Error : (KCLErrorDomain error 0) didFailWithError: Error Domain=kCLErrorDomain Code=0 "The operation couldn’t be completed. (kCLErrorDomain error 0.)"

答案 1 :(得分:0)

来自Apple文档:

Configuration of your location manager object must always occur on a thread with 
an active run loop, such as your application’s main thread.

答案 2 :(得分:0)

尝试重置位置服务,Wifi和网络运营商的设置。有时它是由于提供设备位置的资源设置无效而发生的。