首頁  >  文章  >  後端開發  >  php如何實現騰訊與百度座標的轉換詳解

php如何實現騰訊與百度座標的轉換詳解

黄舟
黄舟原創
2017-08-07 09:30:051661瀏覽

下面小編就為大家帶來一篇PHP實現騰訊與百度座標轉換。小編覺得蠻不錯的,現在就分享給大家,也給大家做個參考。一起跟著小編過來看看吧

廢話不多說,直接上程式碼


public function coordinate_switch($a,$b){//百度转腾讯坐标转换
  $x = (double)$b - 0.0065;
  $y = (double)$a - 0.006;
  $x_pi = 3.14159265358979324;
  $z = sqrt($x * $x+$y * $y) - 0.00002 * sin($y * $x_pi);
  $theta = atan2($y,$x) - 0.000003 * cos($x*$x_pi);
  $gb = number_format($z * cos($theta),15);
  $ga = number_format($z * sin($theta),15);
  return ['Latitude'=>$ga,'Longitude'=>$gb];
}

public function coordinate_switchf($a,$b){//腾讯转百度坐标转换
  $x = (double)$b ;
  $y = (double)$a;
  $x_pi = 3.14159265358979324;
  $z = sqrt($x * $x+$y * $y) + 0.00002 * sin($y * $x_pi);
  $theta = atan2($y,$x) + 0.000003 * cos($x*$x_pi);
  $gb = number_format($z * cos($theta) + 0.0065,6);
  $ga = number_format($z * sin($theta) + 0.006,6);

  return ['Latitude'=>$ga,'Longitude'=>$gb];

}

以上是php如何實現騰訊與百度座標的轉換詳解的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn