Created
October 7, 2018 09:38
-
-
Save abidkhan484/18694bb4c57fe1624d7774dddb6784f4 to your computer and use it in GitHub Desktop.
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 characters
| <?php | |
| function getDistanceFromLatLonInKm() { | |
| // $lat1,$lon1,$lat2,$lon2 | |
| $lat1 = 23.747047; | |
| $lon1 = 90.386709; | |
| $lat2 = 23.783014; | |
| $lon2 = 90.395310; | |
| $R = 6371; // Radius of the earth in km | |
| $dLat = $this->deg2rad($lat2 - $lat1); // deg2rad below | |
| $dLon = $this->deg2rad($lon2 - $lon1); | |
| $a = | |
| sin($dLat/2) * sin($dLat/2) + | |
| cos($this->deg2rad($lat1)) * cos($this->deg2rad($lat2)) * | |
| sin($dLon/2) * sin($dLon/2) | |
| ; | |
| $c = 2 * atan2(sqrt($a), sqrt(1-$a)); | |
| $d = $R * $c; // Distance in km | |
| return $d; | |
| } | |
| function deg2rad($deg) { | |
| return $deg * (pi()/180); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment