Example of mutual conversion between Tencent Map and Baidu Map using PHP

little bottle
Release: 2023-04-06 08:50:02
forward
2497 people have browsed it


The main content of this article is about using PHP to realize the mutual conversion of Tencent Map and Baidu Map (with code). It has certain reference value. Interested friends must take a good look. oh!

/**
* 百度地图---->腾讯地图
* @param double $lat 纬度
* @param double $lng 经度
* @return array();
*/
function Convert_BD09_To_GCJ02($lat,$lng){
        $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);
}

/**
* 腾讯地图---->百度地图
* @param double $lat 纬度
* @param double $lng 经度
*/
function Convert_GCJ02_To_BD09($lat,$lng){
        $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);
}
Copy after login

Related tutorials: PHP video tutorial

The above is the detailed content of Example of mutual conversion between Tencent Map and Baidu Map using PHP. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:cnblogs.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template