Sukeshj
Sukeshj

Reputation: 1503

calculating distance between to location using latitude & longitude

in my application i am collecting latitude and longitude when user dialed call or receive call at that time i am calling one function with NSTimer with delay of 15sec , and again i am collecting latitude and longitude.

the problem is that while i am calculating distance between them it give minimum distance 0.87 miles or 1 miles even if i am not moving i used following formula

double    distance = (sin(gpslatitudeOld/57.2958) * sin(gpslatitudeNew/57.2958)) + (cos(gpslatitudeOld/57.2958) * cos(gpslatitudeNew/57.2958) * cos(gpslongitudeNew/57.2958 - gpslongitudeOld/57.2958));

from site (http://www.meridianworlddata.com/Distance-Calculation.asp)

i also used

[newLocation getDistanceFrom:startingPoint]

but still not getting other result , in one forum i read that there will be up down of 1mile in two latitude and longitude. so is there any solution fro that ???

Upvotes: 1

Views: 1083

Answers (3)

sinh99
sinh99

Reputation: 3979

CLLocation *location1 = [[CLLocation alloc] initWithLatitude:lat1 longitude:long1];
CLLocation *location2 = [[CLLocation alloc] initWithLatitude:lat2 longitude:long2];
NSLog(@"Distance i meters: %f", [location1 distanceFromLocation:location2]);
[location1 release];
[location2 release];

Upvotes: 3

TomH
TomH

Reputation: 2975

Try the aviation formulary website. http://williams.best.vwh.net/avform.htm

There are formulas there to compensate for the roundness of the earth when calculating large distances.

Upvotes: 1

T.E.D.
T.E.D.

Reputation: 44814

The earth is not a perfect sphere, so doing simple trigonometry is going to get you large errors. I believe the problem is that it is actually rather flat at the poles, and kinda bulging in the middle (a lot of us get that problem as we age...)

The typical model that I've seen used to account for this is WSG-84. It is possible your platform already has a library to deal with this though.

Upvotes: 0

Related Questions