问题描述
在iOS 4.0之前, CoreLocation
正确报告高度,现在它总是报告为0英尺。
Prior to iOS 4.0, CoreLocation
was reporting altitude correctly, now it always reports as 0 ft.
-(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];
}
不在设备或模拟器上工作,是否有其他人遇到此问题?
Not working on Device nor Simulator, does anyone else experience this issue?
推荐答案
如果您正在使用 startMonitoringSignificantLocationChanges
,这是iOS新功能4.0,那么你将无法获得高度更新。这种低功耗模式仅使用手机信号塔来计算用户的位置,而且这种方法不会报告高度。
If you're using startMonitoringSignificantLocationChanges
, which was a feature new to iOS 4.0, then you will not get altitude updates. This low-power mode only uses cell towers to figure out a user's location, and this method not report altitude.
更一般地说,iPhone有三种方法来计算你的位置 - 手机信号塔,Wi-Fi和GPS。您只能在使用GPS时获得高度。因此,即使您将 desiredAccuracy
设置设置为非常精确以强制设备使用GPS,如果用户在室内,iPhone可能无法获得GPS信号并将回退到小区或Wi-Fi。在这种情况下,你将无法获得高度。还要考虑使用iPod Touch的用户 - 它只能通过Wi-Fi获取位置,因此也不会报告高度。
More generally, the iPhone has three ways of figuring out your location -- cell towers, wi-fi, and GPS. You will only get altitude when the GPS is being used. So even if you set your desiredAccuracy
setting to be really precise to force the device to use GPS, if a user is indoors the iPhone probably won't be able to get a GPS signal and will fallback to cell or wi-fi. In that case, you won't get an altitude. Also consider users who are on an iPod Touch -- it only has the ability to get a location via wi-fi, and thus also won't report an altitude.
这篇关于iOS CoreLocation Altitude的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!