Skip to content

Instantly share code, notes, and snippets.

@BABAK0T0
Created May 1, 2021 10:51
Show Gist options
  • Save BABAK0T0/7cd851b4a2ff29814210ca55a2b780a7 to your computer and use it in GitHub Desktop.
Save BABAK0T0/7cd851b4a2ff29814210ca55a2b780a7 to your computer and use it in GitHub Desktop.

Revisions

  1. BABAK0T0 created this gist May 1, 2021.
    7 changes: 7 additions & 0 deletions Haversine_Formula.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,7 @@
    const EARTH_RADIUS = 6371; // Earth radius in km

    function distanceBetweenTwoCoordinates(lonA, latA, lonB, latB) {
    const x = (lonB - lonA) * Math.cos((latA + latB) / 2);
    const y = (latB - latA);
    return Math.sqrt( x**2 + y**2 ) * EARTH_RADIUS;
    }