This is a static archive of our old OpenStreetMap Help Site. Please post any new questions and answers at community.osm.org.

city name in reverse geocoding

0

Hi,

I am trying to get city name from reverse geocoding. Problem is for some geo location it is showing city name but for some it is other details like county, suburb. It is hard for me to use the data as it is changing place to place.

Here is the example.

https://nominatim.openstreetmap.org/reverse?lat=24.7040592&lon=77.10249019999999&format=json&json_callback=my_callback&extratags=1

https://nominatim.openstreetmap.org/reverse?format=json&lat=54.9824031826&lon=9.2833114795&zoom=10&extratags=1

https://nominatim.openstreetmap.org/reverse?lat=28.5113627&lon=77.2330641&format=json&json_callback=my_callback&extratags=1

If you check the output of above links then you can see the difference.

Is there any way I can get the Country Name, Zip code, and City name properly.

Thanks

asked 02 May '18, 21:04

Raja07848's gravatar image

Raja07848
11112
accept rate: 0%

1

The example in Denmark isn't in a city, so I think you can't expect a city name there at least.

(03 May '18, 10:50) Hjart

One Answer:

2

That's not possible with Nominatim. The hierarchies in different countries sometimes skip a level (think small countries that don't have states), some countries don't have postal code systems, there's villages without cities (administered by a county instead), etc. On top the underlying OpenStreetMap data might simply be lacking information, or links between places (if the boundary of a city isn't known then it's more or less guessing if a nearby village belongs to the city or not). Your best chance is to treat postal codes as optional. And if a city is not returned choose the country/state/district or even country.

answered 03 May '18, 12:59

mtmail's gravatar image

mtmail
4.8k1574
accept rate: 27%

Source code available on GitHub .