0

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.

1 Answer 1

2

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);

2
  • 1
    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 Jun 18, 2010 at 3:03
  • 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
    – progrmr
    Jun 18, 2010 at 3:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.