欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

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

shiping1 的头像
好多人会问为什么微信高级接口获取的坐标信息位置不准,主要原因不是微信获取的不准,而是微信获取的是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&loc...

返回xml格式的:

http://api.map.baidu.com/geocoder/v2/?ak=E4805d16520de693a3fe707cdc962045&callback=renderReverse&loc...

下面是google的api获取的地址

 

Google Geocoding API 

详细地址:http://code.google.com/intl/zh-CN/apis/maps/documentation/geocoding/


自  http://www.weixin66.net/newsshow.php?cid=4&id=7

普通分类: