【问题标题】:didUpdateToLocation never calleddidUpdateToLocation 从未调用过
【发布时间】:2012-01-11 02:37:24
【问题描述】:

我正在使用模拟器和我的设备来测试它,但无论我做什么,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);

}

有人知道为什么不调用它吗?

【问题讨论】:

    标签: ios xcode mapkit core-location cllocationmanager


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

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

      manager.desiredAccuracy = kCLLocationAccuracyKilometer;      
      

      manager.desiredAccuracy = kCLLocationAccuracyTenMeters; 
      

      而不是

      manager.desiredAccuracy = kCLLocationAccuracyBest;
      

      看看这是否有任何改变。

      当我在 iPhone 上测试与位置相关的应用程序时,大多数情况下将 desiredAccuracy 设置为最佳超时。尤其是当你在室内时。

      【讨论】:

        猜你喜欢
        • 2014-11-30
        • 2012-12-03
        • 1970-01-01
        • 2014-04-21
        • 1970-01-01
        • 1970-01-01
        • 2017-01-19
        • 1970-01-01
        • 2018-03-29
        相关资源
        最近更新 更多