Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find distance from the latitude and longitude of two locations?

Tags:

I have a set of latitudes and longitudes of locations.

  • How to find distance from one location in the set to another?
  • Is there a formula ?
like image 536
ArK Avatar asked Sep 14 '09 06:09

ArK


1 Answers

The Haversine formula assumes a spherical earth. However, the shape of the earh is more complex. An oblate spheroid model will give better results.

If such accuracy is needed, you should better use Vincenty inverse formula. See http://en.wikipedia.org/wiki/Vincenty's_formulae for details. Using it, you can get a 0.5mm accuracy for the spheroid model.

There is no perfect formula, since the real shape of the earth is too complex to be expressed by a formula. Moreover, the shape of earth changes due to climate events (see http://www.nasa.gov/centers/goddard/earthandsun/earthshape.html), and also changes over time due to the rotation of the earth.

You should also note that the method above does not take altitudes into account, and assumes a sea-level oblate spheroid.

Edit 10-Jul-2010: I found out that there are rare situations for which Vincenty inverse formula does not converge to the declared accuracy. A better idea is to use GeographicLib (see http://sourceforge.net/projects/geographiclib/) which is also more accurate.

like image 184
Lior Kogan Avatar answered Oct 20 '22 15:10

Lior Kogan