Nominatim 反向發送:
{
"place_id":118873576,
"licence":"Data ? OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright",
"osm_type":"way",
"osm_id":71122987,
"lat":"48.86742742576341",
"lon":"2.334017224974853",
"display_name":"Rue des Petits Champs, Quartier du Palais Royal, Paris 1er Arrondissement, Paris, ?le-de-France, France métropolitaine, 75001, France",
"address":{
"road":"Rue des Petits Champs",
"city_block":"Quartier du Palais Royal",
"neighbourhood":"Paris 1er Arrondissement",
"suburb":"Paris",
"city_district":"Paris",
"county":"Paris",
"state":"?le-de-France",
"region":"France métropolitaine",
"postcode":"75001",
"country":"France",
"country_code":"fr"},
"boundingbox":["48.8671374","48.8675112","2.3336619","2.3352462"]
}
如果我只想要鄰居,我會這樣做:
if($.inArray("neighbourhood", address) !== -1){
console.log(' neighbourhood only ');
result = address.neighbourhood;
}
一般來說,我只需要城市,但也需要鄰里顯示(最后一個用于首都和大城市)。
if($.inArray("city", response) !== 0){
console.log(' city only ';
result = address.city;
}
我的函式 ($.inArray) 或條件 (!== -1) 似乎是錯誤的,因為即使物件不存在條件回傳 true 并考慮條件
使用這個陣列物件和這兩個條件控制臺顯示:僅鄰域和僅城市(但“城市”不存在)
這個問題可以用其他鍵重復:郊區和城鎮。如果陣列物件中存在兩個或多個鍵物件,則存在沖突并且不顯示(使用相同的條件)
uj5u.com熱心網友回復:
$.inArray用于陣列,in用于物件
if("city" in adress){
console.log(' city only ';
result = address.city;
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/491765.html
上一篇:如何使用R中的條件從另一個df為df$column賦值
下一篇:流量管制-令牌桶與漏桶
