Get distance between 2 points


/ Published in: PHP
Save to your folder(s)

Get the distance between 2 points on a map


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.