0

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

user567
  • 3,712
  • 9
  • 47
  • 80

2 Answers2

4

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.

mharper
  • 3,212
  • 1
  • 23
  • 23
1

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]];
Jim
  • 72,985
  • 14
  • 101
  • 108
  • thank you but I have zero as a result. I think we do not get the longitude and altitude in this way – user567 Dec 12 '11 at 21:35
  • That's the correct way to access altitude data, but altitude data is not available for all location updates. – Jim Dec 12 '11 at 21:43