PHP version to achieve Mars, the German map and Baidu map coordinate transformation

Source: Internet
Author: User
Tags cos sin

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.