PHP騰訊地圖經緯度轉百度地圖經緯度

jopen 9年前發布 | 3K 次閱讀 PHP

/**

  • 中國正常GCJ02坐標---->百度地圖BD09坐標
  • 騰訊地圖用的也是GCJ02坐標
  • @param double $lat 緯度
  • @param double $lng 經度 */ function Convert_GCJ02_To_BD09($lat,$lng){
      $x_pi = 3.14159265358979324 * 3000.0 / 180.0;
      $x = $lng;
      $y = $lat;
      $z =sqrt($x * $x + $y * $y) + 0.00002 * sin($y * $x_pi);
      $theta = atan2($y, $x) + 0.000003 * cos($x * $x_pi);
      $lng = $z * cos($theta) + 0.0065;
      $lat = $z * sin($theta) + 0.006;
      return array('lng'=>$lng,'lat'=>$lat);
    
    }

/**

  • 百度地圖BD09坐標---->中國正常GCJ02坐標
  • 騰訊地圖用的也是GCJ02坐標
  • @param double $lat 緯度
  • @param double $lng 經度
  • @return array(); */ function Convert_BD09_To_GCJ02($lat,$lng){
      $x_pi = 3.14159265358979324 * 3000.0 / 180.0;
      $x = $lng - 0.0065;
      $y = $lat - 0.006;
      $z = sqrt($x * $x + $y * $y) - 0.00002 * sin($y * $x_pi);
      $theta = atan2($y, $x) - 0.000003 * cos($x * $x_pi);
      $lng = $z * cos($theta);
      $lat = $z * sin($theta);
      return array('lng'=>$lng,'lat'=>$lat);
    
    }</pre>
 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!