Skip to content

Instantly share code, notes, and snippets.

@richard512
Last active November 5, 2021 03:23
Show Gist options
  • Save richard512/dd6cd0c258e463b22ece9331435b4f12 to your computer and use it in GitHub Desktop.
Save richard512/dd6cd0c258e463b22ece9331435b4f12 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