Skip to content

Instantly share code, notes, and snippets.

@ajokela
Created October 14, 2011 21:00
Show Gist options
  • Save ajokela/1288322 to your computer and use it in GitHub Desktop.
Save ajokela/1288322 to your computer and use it in GitHub Desktop.
Longitude and Latitude - Distance between points
var R = 6371; // km
var dLat = (lat2-lat1).toRad();
var dLon = (lon2-lon1).toRad();
var lat1 = lat1.toRad();
var lat2 = lat2.toRad();
var a = Math.sin(dLat/2) * Math.sin(dLat/2) +
Math.sin(dLon/2) * Math.sin(dLon/2) * Math.cos(lat1) * Math.cos(lat2);
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