相关阅读
封装函数
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!