亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

從地理編碼地圖 API 獲取區域

從地理編碼地圖 API 獲取區域

PHP
一只斗牛犬 2021-09-18 17:16:33
我正在嘗試從地理編碼 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 回答

?
呼如林

TA貢獻1798條經驗 獲得超3個贊

檢查所有類型address_components是否存在administrative_area_level_1


查看完整回答
反對 回復 2021-09-18
  • 2 回答
  • 0 關注
  • 173 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號