iOS CoreLocation Altitude

Wri*_*sCS 10 iphone core-location ios altitude cllocationdistance

在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];
}
Run Code Online (Sandbox Code Playgroud)

不在设备或模拟器上工作,是否还有其他人遇到此问题?

poe*_*ain 12

如果您正在使用startMonitoringSignificantLocationChanges,这是iOS 4.0的新功能,那么您将无法获得高度更新.此低功耗模式仅使用手机信号塔来确定用户的位置,此方法不报告高度.

更一般地说,iPhone有三种方法可以确定您的位置 - 手机信号塔,Wi-Fi和GPS.您只能在使用GPS时获得高度.因此,即使您将desiredAccuracy设置设置为非常精确以强制设备使用GPS,如果用户在室内,iPhone可能无法获得GPS信号并且将回退到小区或Wi-Fi.在这种情况下,你将无法获得高度.还要考虑使用iPod Touch的用户 - 它只能通过Wi-Fi获取位置,因此也不会报告高度.