views:

28

answers:

3

Keep getting EXC_BAD_ACCESS. Ran NSZombieEnabled and came up with nothing.

In simulator console:

 2010-09-11 23:39:56.876 [19072:207] 1.309789, lat, 103.772196, lon

In device console:

EXC_BAD_ACCESS

The line of code:

 NSLog(@"%f, lat, %f, lon",latitudeString,longitudeString);

What CLManager is doing:

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
 NSLog(@"Entering mlocationmanager did updatetolocation");
    latitudeString = [NSString stringWithFormat:@"%f", newLocation.coordinate.latitude];

    longitudeString = [NSString stringWithFormat:@"%f", newLocation.coordinate.longitude];

  NSLog(@"lat %@ long %@", latitudeString, longitudeString);
 NSLog(@"%@",newLocation.description);
 if (latitudeString.length >0 && longitudeString.length > 0){
  NSLog(@"Yes both are more than 0");
  locationIsReady = YES;

 }
 [self.tableView reloadData]; 
}

What is happening here? Both variables are in my header file and CLLocationManagerDelegate is conformed to. Been working on this for a few hours, but no luck. Hope you guys can help.

NSString *latitudeString;
 NSString *longitudeString;
A: 

The line of code should indeed be your culprit:

NSLog(@"%f, lat, %f, lon",latitudeString,longitudeString);

The correct NSLog format argument for Objective-C objects is %@. %f is for floating-point numbers.

zneak
Oops, forgot to mention. I was trying with %@ before that as well. I've fixed this bug, look below. Thanks for your help anyway.
hakewake
A: 

Finally fixed it after a long while.

Took me some time to realize that NSXMLParser was actually overriding some of my variables (I have no idea why). So in the end, I called CLLocationManager after my XML had parsed. Problem solved.

hakewake
You have no idea why so you moved some code around and now it just happens to work. I think you better find the real cause.
St3fan
Your code is definitely doing something wrong; you've probably just moved the crash somewhere else.
tc.
A: 

You really do not need to convert newLocation.coordinate.longitude to an NSString to print it. Simply use %f in the format string to print them.

Also, when you write:

if (latitudeString.length >0 && longitudeString.length > 0)

You are comparing the length of the strings, which will always be greater than zero. BEcause if the longitude or latitude is zero, the converted string will be @"0.0" which has a length of 3. I suspect what you really want here is:

if (newLocation.coordinate.latitude != 0.0
    && newLocation.coordinate.longitude != 0.0)
St3fan
(0,0) is a perfectly valid coordinate though; it just happens to be in the ocean somewhere.
tc.