Advertisement
Guest User

Untitled

a guest
Jul 19th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. <?php
  2. function distance($lat1, $lon1, $lat2, $lon2, $unit) {
  3.  
  4. $theta = $lon1 - $lon2;
  5. $dist = sin(deg2rad($lat1)) * sin(deg2rad($lat2)) + cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($theta));
  6. $dist = acos($dist);
  7. $dist = rad2deg($dist);
  8. $miles = $dist * 60 * 1.1515;
  9. $unit = strtoupper($unit);
  10.  
  11. if ($unit == "K") {
  12. return (round($miles * 1.609344));
  13. } else if ($unit == "N") {
  14. return ($miles * 0.8684);
  15. } else {
  16. return $miles;
  17. }
  18. }
  19. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement