//百度转高德
public function BdToGd($address){
$address=explode(',',$address);
$bd_lon=$address[0];
$bd_lat=$address[1];
$x_pi = 3.14159265358979324 * 3000.0 / 180.0;
$x = $bd_lon - 0.0065;
$y = $bd_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);
$gg_lon = $z * cos($theta);
$gg_lat = $z * sin($theta);
// 保留小数点后六位
$data['gg_lon'] = round($gg_lon, 6);
$data['gg_lat'] = round($gg_lat, 6);
return $data['gg_lon'].','.$data['gg_lat'];
}
//百度转腾讯(亲测有偏差,包括官方给出得api【腾讯官方坐标转换】也有偏差)
public function BdToTx($address){
$address=explode(',',$address);
$lat=$address[1];
$lng=$address[0];
$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);
}
//腾讯转百度
public function TxToBd($address){
$address=explode(',',$address);
$lat=$address[1];
$lng=$address[0];
$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);
}