Skip to content

Instantly share code, notes, and snippets.

@unitycoder
Created January 5, 2016 10:00
Show Gist options
  • Save unitycoder/571496c9d40555445f9c to your computer and use it in GitHub Desktop.
Save unitycoder/571496c9d40555445f9c to your computer and use it in GitHub Desktop.
Calculate distance between LAT LON values
// calculate distance between two LAT LON values
// Note: In this formula, the latitudes and longitudes are expressed in radians. 6371 is radius of the earth in km
// SOURCE: codinggame.com
var earthRadius = 6371;
var x = (lonB-lonA)*Math.cos((latA+latB)/2);
var y = (latB-latA);
var d = Math.sqrt(x*x+y*y)*earthRadius;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment