Posted By

marzsman on 04/04/11


Tagged

maps longitude distance latitude


Versions (?)

Get distance between 2 points


 / Published in: PHP
 

Get the distance between 2 points on a map

  1. function getDistanceBetweenPoints($latitude1, $longitude1, $latitude2, $longitude2) {
  2. $theta = $longitude1 - $longitude2;
  3. $distance = (sin(deg2rad($latitude1)) * sin(deg2rad($latitude2))) +
  4. (cos(deg2rad($latitude1)) * cos(deg2rad($latitude2)) *
  5. cos(deg2rad($theta)));
  6. $distance = acos($distance);
  7. $distance = rad2deg($distance);
  8. $distance = ($distance * 69.09) * 1.609344;
  9.  
  10. return (round($distance,2));
  11. }

Report this snippet  

You need to login to post a comment.