Created
February 22, 2020 19:26
-
-
Save oleg-andreyev/82ef8b710308c3b2b2fa56712a246493 to your computer and use it in GitHub Desktop.
Revisions
-
oleg-andreyev created this gist
Feb 22, 2020 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,22 @@ /** * Calculates the geodesic distance between two points specified by radian latitude/longitude using the * Haversine formula (hf) */ function hf($lat1, $lng1, $lat2, $lng2) { $R = 6371e3; $lng1 = deg2rad($lng1); $lat1 = deg2rad($lat1); $lng2 = deg2rad($lng2); $lat2 = deg2rad($lat2); $deltaLat = $lng2 - $lng1; $deltaLng = $lat2 - $lat1; $a = (sin($deltaLat / 2) ** 2) + (cos($lng1) * cos($lng2) * (sin($deltaLng / 2) ** 2)); $c = 2 * asin(min(1, sqrt($a))); $d = $R * $c; return $d; }