$x _pi = 3.14159265358979324 * 3000.0/180.0;
Mars coordinate system (GCJ-02) to Baidu coordinate system (BD-09) algorithm
function Bd_encrypt ($gg _lat, $gg _lon)
{
Global $x _pi;
$x = $gg _lon;
$y = $gg _lat;
$z = sqrt ($x * $x + $y * $y) + 0.00002 * sin ($y * $x _pi);
$theta = atan2 ($y, $x) + 0.000003 * cos ($x * $x _pi);
$BD _lon = $z * cos ($theta) + 0.0065;
$BD _lat = $z * sin ($theta) + 0.006;
}
Baidu coordinate system (BD-09) turn Mars coordinate system (GCJ-02) algorithm
function Bd_decrypt ($bd _lat, $BD _lon)
{
Global $x _pi;
$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);
}
Transferred from: http://blog.csdn.net/coolypf/article/details/8569813
http://segmentfault.com/a/1190000000498434
Conversion algorithm of Mars coordinate system (GCJ-02) and Baidu coordinate system (BD-09)