I have two GEO locations. How can I calculate the distance between them?
I have two GEO locations. How can I calculate the distance between them?
GPS coordinates are geographical coordinates on the WGS84 spheroid. Under this model, Vincenty's formulae gives results of sub-millimeter accuracy. For most applications, that's either overkill or actually deceptive, as the earth's surface is not modelled by WGS84 to that scale.
You can compare the accurracy of various methods of distance computation on this page (broken link; check the source code instead). As you can see, the spherical and the differential approximations (the latter uses the Pythagorean theorem with the correct local metric) are inaccurate for a lot of cases.
Of the remaining methods, the first one uses the spheroid's mean radius to convert from geographical to geocentrical latitude, whereas the second one uses the cosine rule to get more accurate results in case of 'small' distances (where the definition of 'small' mainly depends on the difference in latitude).
A seperate script containing only these two methods can be found here, which provides a function called distance()
and expecting four arguments: the two latitudes, the difference in longitude (all in radians) and a boolean flag indicating whether the distance is 'small'.