mysql经纬度 微信_微信如何根据经纬度坐标查询具体地理位置
好多人會(huì)問為什么微信高級(jí)接口獲取的坐標(biāo)信息位置不準(zhǔn),主要原因不是微信獲取的不準(zhǔn),而是微信獲取的是gps坐標(biāo),如果你直接用百度或google的api去解析的話肯定會(huì)出現(xiàn)誤差的。
首先你需要吧gps位置轉(zhuǎn)換成google或者百度的坐標(biāo),然后在通過轉(zhuǎn)換后的坐標(biāo)去獲取準(zhǔn)確的地理位置。
方法一:gps轉(zhuǎn)換成google或者百度坐標(biāo),轉(zhuǎn)換gps的接口 http://map.yanue.net/gps.html
方法二:gps轉(zhuǎn)換成百度坐標(biāo)
function getgps($lats,$lngs, $gps=false, $google=false)//gpg 轉(zhuǎn)百度坐標(biāo)
{
$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);
}
下面是通過百度坐標(biāo)獲取地理位置信息
返回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獲取的地址
總結(jié)
以上是生活随笔為你收集整理的mysql经纬度 微信_微信如何根据经纬度坐标查询具体地理位置的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: java 面向对象继承的思想_Java面
- 下一篇: 苹果发布 Safari 浏览器技术预览版