Skip to content

Instantly share code, notes, and snippets.

@rafaeldjsm
Forked from richard512/geo-distance-calc.md
Created October 26, 2021 18:21
Show Gist options
  • Save rafaeldjsm/f7df56ab930dbbbb605e3649c638229b to your computer and use it in GitHub Desktop.
Save rafaeldjsm/f7df56ab930dbbbb605e3649c638229b to your computer and use it in GitHub Desktop.
Calculate distance between lat long coordinates in excel / libre calc

Using variables

=ACOS(COS(RADIANS(90-Lat1)) *COS(RADIANS(90-Lat2)) +SIN(RADIANS(90-Lat1)) *SIN(RADIANS(90-Lat2)) *COS(RADIANS(Long1-Long2))) *6371

Using Cell References

=ACOS(COS(RADIANS(90-A2)) *COS(RADIANS(90-A3)) +SIN(RADIANS(90-A2)) *SIN(RADIANS(90-A3)) *COS(RADIANS(B2-B3))) *6371

That'll work for a table set up like this:

Name Lat Long
SF 37.7749 -122.4194
Sac 38.5816 -121.4944

Just change A2, A3, B2, B3 to other cells as needed.

Metric, Imperial, or Nautical?

6371 = earth's average radius in kilometers

For miles, substitute 6371 with 3958.756

For nautical miles, use 3440.065

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment