0

Nominatim reverse send that:

{
"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 I want Neighbourhood only I do that :

if($.inArray("neighbourhood", address) !== -1){
                    console.log(' neighbourhood only ');
                    result = address.neighbourhood;
                }

Generally I need only city but neighbourhood display too (This last is used for capital and big city).

if($.inArray("city", response) !== 0){
                    console.log(' city only ';
                    result = address.city;
                }

My function ($.inArray) or the condition (!== -1) seems wrong because even the object doesn't exist the condition return true and consider the condition

With this array object and these two condition the console display: neighbourhood only and city only (but 'city' doesn't exist)

this problem can be repeated with other key : suburb and town. if two or more key object exist inside array object there are a conflict and nothing display (using the same condition)

1 Answer 1

2

$.inArray is for arrays, use in for objects

if("city" in adress){
    console.log(' city only ';
    result = address.city;
}
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks a lot . where is the documentation ? I can't find it . Can I use multiple object in the condition "in" or must I separate them by "&&" ex : if("city, town" in adress){ or : if("city" in adress && "town" in adress){
Documentation developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/… . To check several properties use in in combination with || or &&, so, if("city" in adress && "town" in adress) is ok

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.