Guest User

Untitled

a guest
Jan 21st, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. <?php
  2. function getDistance($point1, $point2){
  3.  
  4. $radius = 3958; // Earth's radius (miles)
  5. $pi = 3.1415926;
  6. $deg_per_rad = 57.29578; // Number of degrees/radian (for conversion)
  7.  
  8. $distance = ($radius * $pi * sqrt(
  9. ($point1['lat'] - $point2['lat'])
  10. * ($point1['lat'] - $point2['lat'])
  11. + cos($point1['lat'] / $deg_per_rad) // Convert these to
  12. * cos($point2['lat'] / $deg_per_rad) // radians for cos()
  13. * ($point1['long'] - $point2['long'])
  14. * ($point1['long'] - $point2['long'])
  15. ) / 180);
  16.  
  17. $distance = round($distance,1);
  18. return $distance; // Returned using the units used for $radius.
  19.  
  20. }
Add Comment
Please, Sign In to add comment