user567
user567

Reputation: 3842

GPS get the longitude and elevation separately

i use this code to get gps data

- (void)locationUpdate:(CLLocation *)location {
    locLabel.text = [location description];
}

the result look like this

<+38.76856432, +11.99454301> +/- 100.00m (speed ......)

when i trie this i have an error,

- (void)locationUpdate:(CLLocation *)location {
    locLabel.text = [location altitude];}

error

Assigng to "NSString *" from incompatible type CLLocationDistance (aka double)

i want to get longitude too

Upvotes: 0

Views: 711

Answers (2)

mharper
mharper

Reputation: 3272

You should be able to get latitude and longitude separately from location.coordinate.latitude and location.coordinate.longitude.

The altitude you are receiving may be invalid. Check the value in location.verticalAccuracy. Per the documentation, "A negative value indicates that the altitude value is invalid." Same goes for location.horizontalAccuracy to make sure the latitude and longitude values in location.coordinate are valid.

Upvotes: 4

Jim
Jim

Reputation: 73936

The altitude property is of type CLLocationDistance, which is a typedef for double. You are trying to assign a number to a property that is expecting a string. You need to create a string representation of the number. Use something like this:

locLabel.text = [NSString stringWithFormat:@"%f", [location altitude]];

Upvotes: 1

Related Questions