didUpdateToLocation从未调用过

时间:2012-01-11 02:37:24

标签: ios xcode mapkit core-location cllocationmanager

我正在使用模拟器和我的设备来测试它,但无论我做什么,都不会调用didUpdateToLocation。我已经尝试在SIM卡中更改我的位置,关闭然后再次使用我的手机上的位置服务来强制手机搜索新位置......没有。在我的viewDidLoad()中,我已经启动了CLLocationManager:

CLLocationManager *manager = [[CLLocationManager alloc] init];

if (![CLLocationManager locationServicesEnabled])    
{
    UIAlertView *servicesDisabledAlert = [[UIAlertView alloc] initWithTitle:@"Location Services Disabled" message:@"You currently have all location services for this device disabled. If you proceed, you will be asked to confirm whether location services should be reenabled." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [servicesDisabledAlert show];

} else {
    manager.desiredAccuracy = kCLLocationAccuracyBest;

    manager.delegate = self;

    [manager startUpdatingLocation];


}

并且在更新位置方法中我有:

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{

NSLog(@"NEW LOCATION! Accuracy:[%f]",newLocation.horizontalAccuracy);

}

有没有人有任何想法为什么没有被召唤?

2 个答案:

答案 0 :(得分:2)

您是否在头文件中添加了位置委托?

答案 1 :(得分:1)

我不知道这是否是问题但请尝试

manager.desiredAccuracy = kCLLocationAccuracyKilometer;      

manager.desiredAccuracy = kCLLocationAccuracyTenMeters; 

而不是

manager.desiredAccuracy = kCLLocationAccuracyBest;

看看是否有任何改变。

当我在iPhone上测试依赖于位置的应用程序时,将desiredAccuracy设置为最佳超时时间。特别是当你在室内时。