百度高德经纬度转换

if(! function_exists('bdEncrypt'))
{
    //GCJ-02(火星,高德)坐标转换成BD-09(百度)坐标
    //@param $longitude 高德经度
    //@param $latitude 高德纬度
    function bdEncrypt($longitude,$latitude){
        $x_pi = 3.14159265358979324 * 3000.0 / 180.0;
        $x = $longitude;
        $y = $latitude ;
        $z = sqrt($x * $x + $y * $y) - 0.00002 * sin($y * $x_pi);
        $theta = atan2($y, $x) - 0.000003 * cos($x * $x_pi);
        $longitude = $z * cos($theta) + 0.0065;
        $latitude = $z * sin($theta) + 0.006;
        // 保留小数点后六位
        $data['lng'] = round($longitude, 6);
        $data['lat'] = round($latitude, 6);
        return $data;
    }
}
if(! function_exists('gdEncrypt')) {
    //BD-09(百度)坐标转换成GCJ-02(火星,高德)坐标
    //@param $longitude 百度经度
    //@param $latitude 百度纬度
    function gdEncrypt($longitude, $latitude)
    {
        $x_pi = 3.14159265358979324 * 3000.0 / 180.0;
        $x = $longitude - 0.0065;
        $y = $latitude - 0.006;
        $z = sqrt($x * $x + $y * $y) - 0.00002 * sin($y * $x_pi);
        $theta = atan2($y, $x) - 0.000003 * cos($x * $x_pi);
        $longitude = $z * cos($theta);
        $latitude = $z * sin($theta);
        $data['lng'] = round($longitude, 6);
        $data['lat'] = round($latitude, 6);
        return $data;
    }
}

 

posted @ 2020-11-21 17:30  CanyingV  阅读(361)  评论(0)    收藏  举报