PHPの経緯度に関する需要例えば計算範囲、距離など


 /**
 *      
 * @param $lon
 * @param $lat
 * @distance   
 * @author xu2019
 */
public static function calculatelonlat($u_lon,$u_la,$distance=5)
 {

     $distance_val = DB::table('m_setting')->where(['set_type'=>'distance'])->value('set_val');
         //       5  5    

     if($distance_val>0)
     {
        $distance = $distance_val;
     }
     $range = 180 / pi() * $distance / 6372.797; 
     $lngR = $range / cos($u_la * pi() / 180);
     $maxLa = $u_la + $range;
     $minLa = $u_la - $range;
     $maxLon = $u_lon + $lngR;
     $minLon = $u_lon - $lngR;

     $list = array('maxLon'=>$maxLon,'minLon'=>$minLon,'maxLa'=>$maxLa,'minLa'=>$minLa);
     return $list;

 }

/**
  *              ,    
  * @param lng1 $ ,lng2   
  * @param lat1 $ ,lat2   
  * @return float   ,   
  * @author xu
  */
  public  static function  checkdistance($lng1, $lat1, $lng2, $lat2) {

     $radLat1 = deg2rad($lat1); 
     $radLat2 = deg2rad($lat2);
     $radLng1 = deg2rad($lng1);
     $radLng2 = deg2rad($lng2);
     $a = $radLat1 - $radLat2;
     $b = $radLng1 - $radLng2;
     $s = 2 * asin(sqrt(pow(sin($a / 2), 2) + cos($radLat1) * cos($radLat2) * pow(sin($b / 2), 2))) * 6378.137 * 1000;
     return intval($s);
 }