Ios6 didUpdateToLocations:永无止境?

Ios6 didUpdateToLocations:永无止境?,ios6,core-location,Ios6,Core Location,基于另一个SO问题,我实现了didUpdateLocations:方法,如下所示: - (void) locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations { // Get the latest location found CLLocation *location = [locations lastObject]; NSTimeInterval loca

基于另一个SO问题,我实现了
didUpdateLocations:
方法,如下所示:

- (void) locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
    // Get the latest location found
    CLLocation *location = [locations lastObject];

    NSTimeInterval locationAge = -[location.timestamp timeIntervalSinceNow];

    if (locationAge > 5.0) return;
    if (location.horizontalAccuracy < 0) return;

    if (_bestEffort == nil || _bestEffort.horizontalAccuracy >= location.horizontalAccuracy) {
        _bestEffort = location;

        // Let the delegate know
        if (self.delegate && [self.delegate respondsToSelector:@selector(location:didUpdateLocationTo:)]) {
            [self.delegate location:self didUpdateLocationTo:location];
        }

        if (location.horizontalAccuracy <= _locationManager.desiredAccuracy) {
            // Great, we've found our final location so stop searching!
            [self stopTrackingLocation];

            // Let our delegate know we've finished our work
            if (self.delegate && [self.delegate respondsToSelector:@selector(location:didFinishTrackingLocationWithFinalLocation:)]) {
                [self.delegate location:self didFinishTrackingLocationWithFinalLocation:location];
            }
        }
    }
}
-(无效)位置管理器:(CLLocationManager*)管理器更新位置:(NSArray*)位置
{
//获取找到的最新位置
CLLocation*location=[locations lastObject];
NSTimeInterval locationAge=-[location.timestamp TimeIntervalenceNow];
如果(位置>5.0)返回;
如果(位置水平精度<0)返回;
如果(_bestforce==nil | | _bestforce.HorizontalAccurance>=location.HorizontalAccurance){
_最佳努力=位置;
//让学员知道
if(self.delegate&&[self.delegate respondsToSelector:@selector(位置:didUpdateLocation:)])){
[self.delegate位置:self-diddupdateLocation:location];
}

如果(location.horizontalAccuracy,问题是您试图获得的位置的水平精度低于您期望的精度

if (location.horizontalAccuracy <= _locationManager.desiredAccuracy) {
iPhone 5的实际水平精度永远不会低于5米。它可以是10、20或50米,具体取决于可见的卫星数量及其几何结构。如果系统根本无法获得修复,它也可以是-1。这就是此行的目的,忽略这些无效位置:

    if (location.horizontalAccuracy < 0) return;
if(location.horizontalcreaction<0)返回;
编辑:
仅当您在CLLocationManager对象上配置
desiredAccuracy
属性时,才应使用常量
KCLLocationAccuracyBestforNavigation
kCLLocationAccuracyBest
设置来配置核心定位硬件,以启用GPS、GLONASS等,以满足您的要求你期望的准确度(不能保证达到)


desiredAccuracy
不是您应该在委托方法中使用的值,它只是用于配置CLLocationManager。

horizontalAccuracy小于0表示该位置无效。为什么您需要的精确度
-2
?它应该是正值,如50或100,取决于ac的多少精度(以米为单位)你需要吗?这就是我的想法,但这正是我得到的。我传递
kClocationAccuracyBestforNavigation
并得到-2,
kClocationAccuracyBest
给出了-1。我把它改为10米,看起来很好,但我仍然不明白为什么另外两个得到-1/-2?1和-2只是常数向CLLocationManager发送您想要的信号。报告位置的水平精度有一个单独的含义。当位置无效时,它将为-1,这是正常的,根据设备的天空净度,您需要几秒钟才能获得一个好的位置。我理解该代码的作用和原因永远不会返回。我只是不太明白为什么导航和最佳精度值是-1和-2,我也找不到任何这样使用它们的例子。我将代码放到了最近的10米处,因为精确定位并不太重要,但我确实希望能够(准确地)检索地址出于导航目的,我在上面的回答中添加了更多内容,以说明您仍然希望使用这些常量,但仅在设置
desiredAccuracy
属性时使用。
    if (location.horizontalAccuracy < 0) return;