Skip to content

Instantly share code, notes, and snippets.

@socialpixe
Forked from dmozzy/CalcDistance.js
Created November 17, 2021 04:42
Show Gist options
  • Save socialpixe/172f48143e1fdf693e753a24e949fab3 to your computer and use it in GitHub Desktop.
Save socialpixe/172f48143e1fdf693e753a24e949fab3 to your computer and use it in GitHub Desktop.
Calculate Distance using google.maps.geometry.spherical.computeDistanceBetween
<script src="http://maps.google.com/maps/api/js?sensor=false&libraries=geometry" type="text/javascript"></script>
<script type="text/javascript">
function calcDistance (fromLat, fromLng, toLat, toLng) {
return google.maps.geometry.spherical.computeDistanceBetween(
new google.maps.LatLng(fromLat, fromLng), new google.maps.LatLng(toLat, toLng));
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment