views:

95

answers:

1

for some reason my code causes my program to crash. does anyone know why or how to fix it?

NSLog(@"here");
CLLocation *location = [locationManager location]; 
[mapView removeAnnotations:mapView.annotations]; 
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; 
CLLocationCoordinate2D workingCoordinate = [location coordinate];
 NSLog(@" this is %@", workingCoordinate.latitude);

it makes it to the first NSLog, but somewhere between the first and second it crashes. My guess is that it has to do with the CLLocation *location line.

+2  A: 

CLLocationCoordinate2D is a struct containing two non-object fields of type CLLocationDegrees. The %@ passed to the NSLog will try to interpret the value as an object reference and that is causing the crash.

Try: NSLog(@" this is %d", workingCoordinate.latitude);

bbum
That allowed the program to work, but it gave a latitude that is impossible: 14212. On my map though it is adding the coordinates of this annotation to Lat 0 long 0
kevin Mendoza
That's because latitude and longitude are double, so you can't use %d, you would use %f format specifier. Check the [CLLocationDegrees definition in the docs](http://developer.apple.com/iphone/library/documentation/CoreLocation/Reference/CLLocation_Class/CLLocation/CLLocation.html)
progrmr
Duh. Of course. Thanks.
bbum