didUpdateToLocation永远不会调用
问题描述:
我正在使用模拟器和我的设备来测试,但不管我做什么,didUpdateToLocation都不会被调用。我曾尝试在SIM卡中更改自己的位置,然后关闭手机上的位置服务,强制手机搜索新位置......没有任何内容。在我的viewDidLoad(),我已经开始CLLocationManager像这样:didUpdateToLocation永远不会调用
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);
}
有没有人有这是为什么没有被调用的任何想法?
答
您是否在您的头文件中添加位置委托?
答
我不知道这是否是问题,但尝试
manager.desiredAccuracy = kCLLocationAccuracyKilometer;
或
manager.desiredAccuracy = kCLLocationAccuracyTenMeters;
,而不是
manager.desiredAccuracy = kCLLocationAccuracyBest;
,并看看是否有任何变化。
当我在我的iPhone上测试与位置有关的应用程序时,将期望的精度设置为最佳超时时间。特别是当你在室内时。
我怎么错过了?谢谢。 – 2012-01-11 02:47:12
我很高兴我可以帮助... – AAV 2012-01-11 03:30:25