Advertisement
Guest User

Untitled

a guest
Sep 16th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.48 KB | None | 0 0
  1. function deg2Radius($deg) {
  2. return $deg * M_PI / 180;
  3. }
  4.  
  5. function getDistanceMeter($lat1, $lon1, $lat2, $lon2) {
  6. $R = 6371;
  7. $dLat = deg2Radius($lat2 - $lat1);
  8. $dLon = deg2Radius($lon2 - $lon1);
  9. $a = sin($dLat / 2) * sin($dLat / 2) + cos(deg2Radius($lat1)) * cos(deg2Radius($lat2)) * sin($dLon / 2) * sin($dLon / 2);
  10. $c = 2 * atan2(sqrt($a), sqrt(1 - $a));
  11. $d = $R * $c;
  12. return $d * 1000;
  13. }
  14.  
  15.  
  16. //EXAMPLE
  17. getDistanceFromLatLonInMeter(lat1,long1,lat2,long2);
  18. // xxxx METER
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement