百度地图坐标转化为GPS坐标

// /**
// * @date:2017-07-12 10:57
// * @auth:百度地图文档
// * 百度坐标系转换成标准GPS坐系
// * @param float $lnglat 坐标(如:106.426, 29.553404)
// * @return string 转换后的标准GPS值:
// */
function BD09LLtoWGS84($lnglat){ // 经度,纬度
$lnglat = explode(',', $lnglat);
list($x,$y) = $lnglat;
$Baidu_Server = "http://api.map.baidu.com/ag/coord/convert?from=0&to=4&x={$x}&y={$y}";
$result = @file_get_contents($Baidu_Server);
$json = json_decode($result);
if($json->error == 0){
$bx = base64_decode($json->x);
$by = base64_decode($json->y);
$GPS_x = 2 * $x - $bx;
$GPS_y = 2 * $y - $by;
return $GPS_x.','.$GPS_y;//经度,纬度
}else{
return $lnglat;
}
}

猜你喜欢

转载自www.cnblogs.com/wangyaoyu/p/9431022.html