Skip to content

Instantly share code, notes, and snippets.

@hughes
Created September 16, 2014 14:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hughes/2e8eda0cf05687ce95f1 to your computer and use it in GitHub Desktop.
Save hughes/2e8eda0cf05687ce95f1 to your computer and use it in GitHub Desktop.
Unicode variable names...
var R = 6371; // km
var φ1 = lat1.toRadians();
var φ2 = lat2.toRadians();
var Δφ = (lat2-lat1).toRadians();
var Δλ = (lon2-lon1).toRadians();
var a = Math.sin(Δφ/2) * Math.sin(Δφ/2) +
Math.cos(φ1) * Math.cos(φ2) *
Math.sin(Δλ/2) * Math.sin(Δλ/2);
var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
var d = R * c;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment