php通过地址获得百度地图经纬度(逆地理编码)

相关阅读

php通过地址获得百度地图经纬度(逆地理编码)

封装函数

function getLoLa($lat, $lng)
{
	$points  = $lat . ',' . $lng;
	$baiduAK = 'http://api.map.baidu.com/reverse_geocoding/v3/?ak=11Z8uiP8kIz6AG0Vjiwzbc5f9I&output=json&coordtype=bd09ll&location=' . $points . '';
	$lola    = file_get_contents($baiduAK);
	return $lola;
}

$lat  = '31.225696';
$lng  = '121.498840';
$info = json_decode(getLoLa($lat, $lng), true);

echo $info['result']['addressComponent']["province"];
echo $info['result']['addressComponent']["city"];
echo $info['result']['addressComponent']["district"];
echo $info['result']['addressComponent']["street"];
echo $info['result']['addressComponent']["street_number"];

返回数据格式

{
    "status": 0,
    "result": {
        "location": {
            "lng": 121.49883999999993,
            "lat": 31.225696365806976
        },
        "formatted_address": "上海市黄浦区净土街31弄-4号",
        "business": "老西门,城隍庙,西藏南路",
        "addressComponent": {
            "country": "中国",
            "country_code": 0,
            "country_code_iso": "CHN",
            "country_code_iso2": "CN",
            "province": "上海市",
            "city": "上海市",
            "city_level": 2,
            "district": "黄浦区",
            "town": "",
            "town_code": "",
            "adcode": "310101",
            "street": "净土街",
            "street_number": "31弄-4号",
            "direction": "北",
            "distance": "58"
        },
        "pois": [],
        "roads": [],
        "poiRegions": [],
        "sematic_description": "",
        "cityCode": 289
    }
}

lockdatav done!

已标记关键词 清除标记
相关推荐
©️2020 CSDN 皮肤主题: 精致技术 设计师:CSDN官方博客 返回首页