Skip to content

Instantly share code, notes, and snippets.

@arumoy
Created December 7, 2016 18:50
Show Gist options
  • Save arumoy/d57b19089d577094a0298e2b640e93ae to your computer and use it in GitHub Desktop.
Save arumoy/d57b19089d577094a0298e2b640e93ae to your computer and use it in GitHub Desktop.
Great Circle Distance calculator in JS
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false&libraries=geometry"></script>
<script>
var p1 = new google.maps.LatLng(12.851853, 77.664216);
var p2 = new google.maps.LatLng(12.851854, 77.664219);
alert(calcDistance(p1, p2));
//calculates distance between two points in km's
function calcDistance(p1, p2) {
return (google.maps.geometry.spherical.computeDistanceBetween(p1, p2)).toFixed(10);
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment