我正在尝试从地理编码 api 谷歌地图中获取区域名称。我可以使用以下代码获得经度和纬度:$address ="London";$coordinates = file_get_contents('https://maps.googleapis.com/maps/api/geocode/json?key=API_KEY_HERE&address=' . urlencode($address) . '&sensor=true');$coordinates = json_decode($coordinates);$latitude = $coordinates->results[0]->geometry->location->lat;$longitude = $coordinates->results[0]->geometry->location->lng;我从 google api 得到的信息是{ "results" : [ { "address_components" : [ { "long_name" : "London", "short_name" : "London", "types" : [ "locality", "political" ] }, { "long_name" : "London", "short_name" : "London", "types" : [ "postal_town" ] }, { "long_name" : "Greater London", "short_name" : "Greater London", "types" : [ "administrative_area_level_2", "political" ] }, { "long_name" : "England", "short_name" : "England", "types" : [ "administrative_area_level_1", "political" ] }, { "long_name" : "United Kingdom", "short_name" : "GB", "types" : [ "country", "political" ] } ],我想获得该地区(在本例中),England这是最好的方法吗?
- 2 回答
- 0 关注
- 145 浏览
添加回答
举报
0/150
提交
取消