开发者

altitude property in location manager returning zero on Iphone when reading GPS Location

I am writing an app, that uses GPS. I can get success开发者_Python百科fully 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


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜