LatLng Distance

Benchmark created by Aaron F on


Preparation HTML

<script src="//maps.google.com/maps/api/js?sensor=false&libraries=geometry"></script>
<script>
  RADIUS_OF_EARTH = 6378137;
  
  var deg2rad = function(degrees) {
   return Math.PI * (degrees / 180);
  }
  
  var distance = function(aLat, aLon, bLat, bLon) {
   var dlat = aLat - bLat,
       dlon = aLon - bLon,
       a = Math.pow(Math.sin(deg2rad(dlat / 2)), 2) + Math.cos(deg2rad(aLat)) * Math.cos(deg2rad(bLat)) * Math.pow(Math.sin(deg2rad(dlon / 2)), 2);
  
   return RADIUS_OF_EARTH * 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
  }
  
  var siberia = new google.maps.LatLng(60, 105);
  var newyork = new google.maps.LatLng(40.69847032728747, -73.9514422416);
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
Google Maps
google.maps.geometry.spherical.computeDistanceBetween(siberia, newyork);
ready
My Shit
distance(siberia.lat(), siberia.lng(), newyork.lat(), newyork.lng());
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.