0

I am writing an app, that uses GPS. I can get successfully the latitude, longitude and other properties, but altitude seems to always return "0.00" i have the following code to test it in the most simplest way and still get 0.00. Code below:

-(void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
       fromLocation:(CLLocation *)oldLocation
{


// Stop updating location if renewed in less than 60 seconds
    if ([self timeBetweenLocationandNow] < 60)
{
    [locationManager stopUpdatingLocation]; 
    NSLog(@"GPS Stopped");
}


NSLog(@"Altitude:%.2f m",newLocation.altitude);
}

Any ideas on what could be wrong ? also on an init method i have the following:

- (id)init
{
self = [super init];

if (self != nil)
{
    // Create location manager Object
    locationManager = [[CLLocationManager alloc] init];
    // Set the delegate to this object
    [locationManager setDelegate:self];
    // Set distance filter and accuracy 
    [locationManager setDesiredAccuracy:kCLLocationAccuracyBest];
    [locationManager startUpdatingLocation];
 }

return self;
}

Will appreciate any insight. thank you

2 Answers 2

0

I'm no expert but this is how I understand it: The iPhone is quite different from other gps systems because of the multiple ways in which it goes about figuring out your location. The iPhone figures out the location in three ways: local wifi signals, cell towers, and/or gps chip. Using a gps satellite to find a position can be extremely slow and reception can be pretty much non-existent in populated cities. Therefore, iPhone generally looks to the first 2 options first.

Wifi positioning data comes from people driving around on the streets logging hotspots which obviously isn't going to give much of a hint of an altitude. I'm not sure if cell tower triangulation gives any altitude data but my guess is no. These two methods are extremely fast compared to gps but will yield an altitude of 0 as you have seen. If you are in a place where there is a decent gps satellite reception the iPhone may give you the altitude, but even then, it might not even find it till it has received the satellite signal a few times and called the location delegate multiple times, and even then altitude data for gps can be notoriously inaccurate.

Long story short, it's a bad idea to count on accurate altitude data from the iPhone.

1
  • Somewhere I read that civilian GPS is only accurate to +- 15 meters 95% of the time. GPS tends to be slow when the receiver has not seen satellites for extended periods of time.
    – dbasnett
    Apr 3, 2011 at 14:00
0

i found the problem. As Deepmist suggested the delegate has to be called several times. I was stopping the GPS after the first fix. Which was giving me accurate data for coordinates but altitude remained @ 0.00 until like 3 or so delegate calls. Now i get the altitude data, what is a good way to check for this ? so i can stop the location manager after i get the data ? i can check that altitude is a non-zero value, but was wondering if there are other properties that should be used instead to make sure that you have the highest accuracy possible making all of your location data valid (i.e non-zero on some properties). thank you

1
  • Can u pls post the code How u succeeded getting the altitude value.Im struggling with it. Apr 20, 2011 at 10:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.