开发者

DistanceFromLocation producing extremely large (incorrect) distance

I've been having the hardest time trying to figure out why distanceFromLocation isn't calculting the correct distance for two CLLocations. The calculated result is a number WAY larger than the actual distance but the two locations appear to be valid locations.

First of all, here are the two locations:

LOCATION 1: <+44.56697840, -69.55759810> +/- 0.00m (speed -1.00 mps / course -1.00) @ 2010-12-13 21:12:03 -0500

LOCATION 2: <+44.31400400, -69.79157000> +/- 0.00m (speed -1.00 mps / course -1.00) @ 2010-12-13 21:12:03 -0500

And here is the code where Location1 and Location2 are being declared. I've verified that these are the correct values, but I still can't figure this out

CLLocation *newLocation = [[CLLocation alloc] 
    i开发者_运维技巧nitWithLatitude:[latitude doubleValue] 
    longitude:[longitude doubleValue]];
    // CURRENT LOCATION (OR SEARCHED LOCATION)

double dLat = 0;
int tmpDistance = 0;
id returnId = nil;

id tmp = [featuredResults objectAtIndex:i];
CLLocation *newLocation2 = [[CLLocation alloc] 
    initWithLatitude:[[tmp valueForKey:@"lat"] doubleValue]  
    longitude:[[tmp valueForKey:@"lng"] doubleValue]];

dLat = [newLocation distanceFromLocation:newLocation2];

The value that I'm getting for dLat is 330707027, which is way wrong. Does anyone know where I might be going wrong? Thanks!


This test code based on the one in the question gives about 33,669 meters:

CLLocation *newLocation = [[CLLocation alloc] 
    initWithLatitude:44.56697840 longitude:-69.55759810];

CLLocation *newLocation2 = [[CLLocation alloc] 
    initWithLatitude:44.31400400 longitude:-69.79157000];

double dLat = [newLocation distanceFromLocation:newLocation2];

NSLog(@"distance = %f meters", dLat);

[newLocation release];
[newLocation2 release];

Output:

distance = 33669.002406 meters

Perhaps you are logging dLat using something other than %f?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜