百度经纬度和火星坐标转换

hykeda8年前PHP1125
<?php
    //GCJ-02(火星,高德) 坐标转换成 BD-09(百度) 坐标
      //@param bd_lon 百度经度
    //@param bd_lat 百度纬度
    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(百度) 坐标转换成  GCJ-02(火星,高德) 坐标
      //@param bd_lon 百度经度
    //@param bd_lat 百度纬度
    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;
    }
    //测试
    $bd = bd_encrypt(108.947903,34.231966);
    //输出:array(2) { ["bd_lon"]=> float(108.954466795) ["bd_lat"]=> float(34.2376965936) }
    $gg = bd_decrypt(108.95434,34.238235);
    //输出:array(2) { ["gg_lon"]=> float(108.947903625) ["gg_lat"]=> float(34.2319662425) }
?> 

API

坐标系

百度地图API

百度坐标

腾讯搜搜地图API

火星坐标

搜狐搜狗地图API

搜狗坐标

阿里云地图API

火星坐标

图吧MapBar地图API       

图吧坐标

高德MapABC地图API

火星坐标

灵图51ditu地图API

火星坐标

坐标解释:

1、GCJ-02,国测局02年发布的坐标体系。又称“火星坐标”。谷歌,腾讯,高德都在用这个坐标体系。

2、BD-09,百度坐标系。

相关文章

php 用curl 进行数据post给接口,如何将数据存放至body中传递

有个项目,将数据推送至接口文件,代码入下:$headers[]  =  "Accept:application/json";$headers[]  =...

file_get_contents("php://input")的使用方法

$data = file_get_contents("php://input"); php://input 是个可以访问请求的原始数据的只读流。 POST 请求的情况下,最好使用 php:/...

php导出EXCEL出现错误解决方法

由于数据量不多的增多,最近出现了导出excel的时候报错:Allowed memory size of 134217728 bytes exhausted (tried to allocate 114...

抓取页面出现乱码

在抓取页面的时候出现类似�������这样乱码解决方法如下 1、转换编码 str=mbconvertencoding(str=mbconvertencoding(...

discuzX3.2 用户注册接口代码

新建一个php文件在根目录,例:test.php test.php 具体内容: error_reporting(0); require_once './source/class/clas...

关于PHP处理BOM头的问题

关于php出现无法解析数据,直接var_dump出来为string(3)"",必须警觉,极大可能就是存在bom头的问题,比如接收json数据 $rt = json_decode($r...

发表评论    

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。