Skip to content

Instantly share code, notes, and snippets.

@abarth500
Created June 1, 2012 10:07
Show Gist options
  • Save abarth500/2850927 to your computer and use it in GitHub Desktop.
Save abarth500/2850927 to your computer and use it in GitHub Desktop.
Distance between two points
function getDistance(point1,point2){
var my = ((point1.lat + point2.lat) / 2.0) * Math.PI / 180.0;
var dy = (point1.lat - point2.lat) * Math.PI / 180.0;
var dx = (point1.lng - point2.lng) * Math.PI / 180.0;
var w = Math.sqrt(1.0 - 0.0066943799901975 * Math.pow(Math.sin(my),2));
return Math.sqrt(Math.pow(dy * 6335439.32729246 / Math.pow(w,3),2)
+ Math.pow(dx * 6378137.000 * Math.cos(my) / w,2));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment