根據互聯網地圖服務規定,國內互聯網地圖必須使用國測局加密的gcj02座標系,php
高德和谷歌在中國的座標都是這一座標系,能夠互通,谷歌的地圖數據就是高德提供的。加密
百度在gcj02的基礎上,又作了一次加密,座標系跟高德、谷歌不一樣。code
/** * 中國正常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('lat'=>$lat,'lng'=>$lng); } /** * 百度地圖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('lat'=>$lat,'lng'=>$lng); }