CLLocationDistance NaN

Posted by Kaspa on Stack Overflow See other posts from Stack Overflow or by Kaspa
Published on 2009-07-23T11:28:15Z Indexed on 2010/05/29 21:12 UTC
Read the original article Hit count: 397

Filed under:

Hi,

I'm trying to calculate a distance between two sets of coordinate points in an iPhone application on the fly using

 - (CLLocationDistance)getDistanceFrom:(const CLLocation *)location

I saw that I started getting NaN's in strange places, thus investigated the matter up close, with the following hardcoded values.

CLLocationDistance testDistance;
placeLocation = [[CLLocation alloc] initWithLatitude:12.236533 longitude:11.011419];
userLocation = [[CLLocation alloc] initWithLatitude:12.236533 longitude:11.011419];	
testDistance = [userLocation getDistanceFrom:placeLocation];
if(isnan(testDistance))
	NSLog(@"ISNaN!");

[placeLocation release];
[userLocation release];

The above gets called multiple times, and in some situations the testDistance is NaN.

I fear I'm missing something very simple here. Anyone have any idea?

UPDATE 1:

Ok, so I've moved the above code into a new project (put everything in the app delegate), looped it for 100 times and all is fine. This thus suggests that the problem is project related, but this helps very little... since all the variables are in the scope of 1 function.

THE SOLUTION:

OK, this seems to be a simulator bug. The same code build runs perfectly fine on the device. Case solved.

© Stack Overflow or respective owner

Related posts about iphone