Gold map and Baidu map coordinates conversion PHP program
| The code is as follows |
Copy Code |
|
<?php
GCJ-02 (Mars, German) coordinates converted into BD-09 (Baidu) coordinates
@param bd_lon Baidu Longitude
@param bd_lat Baidu Latitude
function Bd_encrypt ($gg _lon, $gg _lat)
{
$x _pi = 3.14159265358979324 * 3000.0/180.0;
$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);
$data [' bd_lon '] = $z * cos ($theta) + 0.0065;
$data [' bd_lat '] = $z * sin ($theta) + 0.006;
return $data;
}
BD-09 (Baidu) coordinates converted into GCJ-02 (Mars, Gould) coordinates
@param bd_lon Baidu Longitude
@param bd_lat Baidu Latitude
function Bd_decrypt ($bd _lon, $BD _lat)
{
$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);
$data [' gg_lon '] = $z * cos ($theta);
$data [' gg_lat '] = $z * sin ($theta);
return $data;
}
Test
$BD = Bd_encrypt (108.947903,34.231966);
Output: Array (2) {["Bd_lon"]=> float (108.954466795) ["Bd_lat"]=> Float (34.2376965936)}
$gg = Bd_decrypt (108.95434,34.238235);
Output: Array (2) {["Gg_lon"]=> float (108.947903625) ["Gg_lat"]=> Float (34.2319662425)}
?>
|
Coordinate explanation:
1, GCJ-02, National Survey Bureau 02 issued the coordinate system. Also known as "Mars coordinates." Google, Tencent, and Gould are using this coordinate system.
2, BD-09, Baidu coordinate system.