block by joyrexus 8438864

Get distance between two lat-lon points

Calculate distance, bearing and more between Latitude/Longitude points

This page presents a variety of calculations for latitude/longitude points, with the formulae and code fragments for implementing them.

<script src="latlon.js"></script> // Latitude/Longitude formulae
<script src="geo.js"></script>    // Geodesy representation conversions
<script>
  var p1 = new LatLon(51.5136, -0.0983);
  var p2 = new LatLon(51.4778, -0.0015);
  var dist = p1.distanceTo(p2);   // in km
  var bear = p1.bearingTo(p2);    // in degrees clockwise from north
</script>

See also the same author’s page illustrating the use of the spherical law of cosines for selecting points from a database within a specified bounding circle.

geo.js

latlon.js