现在的位置: 首页 > 综合 > 正文

GPS经纬度转换为百度坐标

2013年09月02日 ⁄ 综合 ⁄ 共 505字 ⁄ 字号 评论关闭

GPS经纬度转换为百度坐标

1.PHP
<?php
function getgps($lats,$lngs, $gps=false, $google=false)
{
    $lat=$lats;
    $lng=$lngs;
    if($gps)
        $c=file_get_contents("http://api.map.baidu.com/ag/coord/convert?from=0&to=4&x=$lng&y=$lat");
    else if($google)
        $c=file_get_contents("http://api.map.baidu.com/ag/coord/convert?from=2&to=4&x=$lng&y=$lat");
    else 
    return array($lat,$lng);
    $arr=(array)json_decode($c);
    if(!$arr['error'])
    {
        $lat=base64_decode($arr['y']);
        $lng=base64_decode($arr['x']);
    }
    return array($lat,$lng);
}
?>

抱歉!评论已关闭.