Reputation: 2209
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.
Upvotes: 2
Views: 3465
Reputation: 2209
THE SOLUTION:
OK, this seems to be a simulator bug. The same code build runs perfectly fine on the device. Case solved, how do you file a bug with Apple?
Upvotes: 1
Reputation: 6373
You are saying that you actually get NaN when the two locations have the exact same lat/long? Wow...
One thing you might do is test the reverse -- if you DO get NaN, try reversing the two CLLocations:
testDistance = [placeLocation getDistanceFrom: userLocation];
and see if the result always matches; i.e., always either NaN for both ways, or NOT NaN for both ways.
Another thing to check would be what happens when you test
testDistance = [userLocation getDistanceFrom: userLocation];
I'm sorry this isn't an answer, but maybe we can get some more clues.
Upvotes: 1