krot

geo midpoint

Apr 10th, 2019
116
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function midpoint ($lat1, $lng1, $lat2, $lng2) {
  2.         $lat1= deg2rad($lat1);
  3.         $lng1= deg2rad($lng1);
  4.         $lat2= deg2rad($lat2);
  5.         $lng2= deg2rad($lng2);
  6.  
  7.         $dlng = $lng2 - $lng1;
  8.         $Bx = cos($lat2) * cos($dlng);
  9.         $By = cos($lat2) * sin($dlng);
  10.         $lat3 = atan2( sin($lat1)+sin($lat2),
  11.         sqrt((cos($lat1)+$Bx)*(cos($lat1)+$Bx) + $By*$By ));
  12.         $lng3 = $lng1 + atan2($By, (cos($lat1) + $Bx));
  13.         $pi = pi();
  14.                 return array('lng'=>($lat3*180)/$pi , 'lat'=>($lng3*180)/$pi);
  15.     }
RAW Paste Data