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;
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)
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.
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.
精彩评论