Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting Altitude(height from sea level) of my location in iphone SDK

I am trying to get Altitude of my location in my application. But every time I try altitude property of CLLocation object I am getting 0.00 as result.

I googled for my query and I got a similar question here and here. This link is saying that if I access CLLocation with wifi or cell tower it will be null. Even if I try to set desireAccuracy to best than even it don't make sure that app will use GPS. It is also saying that if I am indoor that I won't be able to access GPS.

I many cases it its not sure that app will use GPS only. I want some way for getting Altitude from wifi or cell tower too. For that I googled more and I got Google Earth API but I think this is for Microsoft .net technology only.

Now according to this situation I think for a solution I can create a web service in Microsoft Technology and pass my location there and I can get altitude as response but I don't want to do this.

Can anyone suggest me how to get my location's altitude from ios. Is there any way available or not? If yes than please navigate me in right direction.

Thanks in advance.

Edit1

I used CLLocationManager for updating location and when I get my location I need altitude.

Edit2

According to @fishinear's answer I tried following code:

- (void)viewDidLoad
{
    [super viewDidLoad];
    manager = [[CLLocationManager alloc] init];
    [manager setDesiredAccuracy:kCLLocationAccuracyBestForNavigation];
    [manager setDistanceFilter:kCLDistanceFilterNone];
    [manager setDelegate:self];
    [manager startUpdatingLocation];
// Do any additional setup after loading the view, typically from a nib.
}

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
    if ([newLocation verticalAccuracy] >= 0) {
        NSLog(@"Altitude = %lf",newLocation.altitude);
    }
    NSLog(@"Vertical Accuracy : %lf",newLocation.verticalAccuracy);
}

verticalAccuracy is always -1. It is not changing even after running the app to last 30 Mins. I am runnin ios 4.3.2 on my 3GS. I am indoor so I think it is not accessing GPS using this code even.

like image 305
Kapil Choubisa Avatar asked May 17 '12 06:05

Kapil Choubisa


1 Answers

To answer your original question: GPS will always be used if you set desiredAccuracy to Best or BestForNavigation, and distanceFilter to kCLDistanceFilterNone when configuring the CLLocationManager. You will then also get altitude values in the CLLocation event.

However, it takes a short while before the GPS has "locked in" to enough satelites to be able to report the altitude. During that time it will report CLLocation events without altitude values. Therefore, you should ignore the first couple of events until the verticalAccuracy value is good enough for you. Also, check the timestamp, because sometimes the first CLLocation event is an old one.

like image 177
fishinear Avatar answered Sep 30 '22 13:09

fishinear