Iphone 核心定位高度

Iphone 核心定位高度,iphone,ios,core-location,altitude,cllocationdistance,Iphone,Ios,Core Location,Altitude,Cllocationdistance,在iOS 4.0之前,CoreLocation正确地报告了高度,现在它总是报告为0英尺 -(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation*)newLocation fromLocation:(CLLocation *)oldLocation { NSString *tLatitude = [NSString stringWithFormat:@"%3.5f", ne

在iOS 4.0之前,
CoreLocation
正确地报告了高度,现在它总是报告为0英尺

-(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation*)newLocation fromLocation:(CLLocation *)oldLocation 
{ 
    NSString *tLatitude  = [NSString stringWithFormat:@"%3.5f", newLocation.coordinate.latitude]; 
    NSString *tLongitude = [NSString stringWithFormat:@"%3.5f", newLocation.coordinate.longitude];
    /*  the following returns 0 */
    NSString *tAltitude  = [NSString stringWithFormat:@"%i",    newLocation.altitude];

    /* theres more code, but it's not relevant, 
                      and this worked prior to iOS 4.0*/
    [manager stopUpdatingLocation];
}
不在设备或模拟器上工作,是否有其他人遇到此问题?

来自:


CLLocationDistance
数据类型(高度的数据类型)是一个
double
。用于
stringWithFormat
的格式化程序是一个
整数。首先,您需要将高度转换为整数,或者使用双精度(%f)格式化程序。

您可以尝试两种方法。首先,尝试将位置管理器的
desiredAccuracy
设置为
KCallocationAccuracyBest


如果不起作用,请尝试删除
[manager stopUpdatengLocation],并将
NSLog
与高度一起放入
didUpdateToLocation
。有时在显示高度之前,它需要缩小一点

核心位置并不总是立即报告高度。我通常在我的“成功”委派方法中检查零高度。如果高度仍然为0,我会继续检查,否则,我会转到CoreLocation

如果您使用的是iOS 4.0新增的
startMonitoringSignificantLocationChanges
,则您将无法获得高度更新。这种低功耗模式只使用基站来确定用户的位置,这种方法不报告高度


更一般地说,iPhone有三种确定位置的方法——手机发射塔、wi-fi和GPS。只有在使用GPS时,您才能获得高度。因此,即使您将
desiredAccuracy
设置为非常精确,以强制设备使用GPS,如果用户在室内,iPhone也可能无法获得GPS信号,并会退回到手机或wi-fi。那样的话,你就得不到高度了。也可以考虑在iPod touch上的用户——它只有通过Wi-Fi获得位置的能力,因此也不会报告高度。

我将高度转换成整数。正如我所说的,在iOS 4.0之前,它工作得非常好(即没有代码更改)。此外,我使用它/给我/我完美的高度,用于显示例如5280 ft.@WrightsCS。您是否尝试过建议的双格式设置器,以查看这是否有区别?KCallocationAccuracyBest始终处于设置状态,删除StopUpdateLocation没有任何效果。您是在设备上测试还是在模拟器上测试?