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?
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.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.