(转)微信获取到的经纬度坐标不精准的问题

(转自:风行天下 http://www.cnblogs.com/php-linux/p/4730744.html)

微信如何根据经纬度坐标查询具体地理位置

好多人会问为什么微信高级接口获取的坐标信息位置不准,主要原因不是微信获取的不准,而是微信获取的是gps坐标,如果你直接用百度或google的api去解析的话肯定会出现误差的。

首先你需要吧gps位置转换成google或者百度的坐标,然后在通过转换后的坐标去获取准确的地理位置。

方法一:gps转换成google或者百度坐标,转换gps的接口 http://map.yanue.net/gps.html

 

方法二:gps转换成百度坐标

function getgps($lats,$lngs, $gps=false, $google=false)//gpg 转百度坐标
{
    $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);
}   

 

下面是通过百度坐标获取地理位置信息

 

返回josn格式的:

http://api.map.baidu.com/geocoder/v2/?ak=E4805d16520de693a3fe707cdc962045&callback=renderReverse&location=39.983424,116.322987&output=json&pois=1

返回xml格式的:

http://api.map.baidu.com/geocoder/v2/?ak=E4805d16520de693a3fe707cdc962045&callback=renderReverse&location=39.983424,116.322987&output=xml&pois=1

下面是google的api获取的地址

posted @ 2015-10-06 17:30  __戏谑  阅读(4563)  评论(0编辑  收藏  举报