NOTICE: is no longer in use from 1st March 2024. Please use the OpenStreetMap Community Forum

Hello, I have a GPS coordinates list and I want to retrieve the corrisponding cities.

I'm making calls to Nominatim service, like this:

The response in this case is:

{"place_id":"32590342","licence":"Data © OpenStreetMap contributors, ODbL 1.0.","osm_type":"node","osm_id":"2785042716","lat":"30.4573699","lon":"-97.8247654","display_name":"Nagoya Steak & Sushi, 11630, RM 620, Anderson Mill, Austin, Williamson County, Texas, 78713, USA","address":{"restaurant":"Nagoya Steak & Sushi","house_number":"11630","road":"RM 620","neighbourhood":"Anderson Mill","city":"Austin","county":"Williamson County","state":"Texas","postcode":"78713","country":"USA","country_code":"us"},"boundingbox":["30.4572699","30.4574699","-97.8248654","-97.8246654"]}

So I can just get the value of city property and obtain the city. What about getting the city when the response doesn't have city property?

According to this answer, I see that I can get other properties, such as town, village, suburb, locality, hamlet and so on... but what is the best? If Nominatim response doesn't have city what property should I look for? And if even that property doesn't appear what should be the next property to try to get the value from?

Can you make a list of these properties, ordered by frequency or relevance?

In addition, what about places that doesn't have any address property? Here is some examples:

How to deal with them?

Generally speaking, what is the best strategy to ALWAYS get a city from GPS coordinates?

asked 01 Mar '19, 16:24

Andreanovenove's gravatar image

accept rate: 0%

edited 02 Mar '19, 14:10

The ALWAYS isn't possible. You might get close, but unless you change the definition of city you have to deal with empty data in your data model.

  • Not every place (or address) in the world is assigned to a city. People living on small islands will use the name of the island as logical administrative label in their address, it doesn't make it a city.

  • A city can be multiple types of place. Especially large metropolitan areas are often both city and county, sometimes city and state (Berlin), sometimes city and country (Monaco). OSM data only allows setting one type. In rare cases two places exist in OSM data overlapping each other (same exact boundaries).

  • OSM data might be missing (explicit) assignments of streets to their city (e.g. with address tagging) or OSM data doesn't contain boundaries of a city. Other than guessing by distance it's unclear where some houses belong to.

  • Nominatim might not return the city field correctly. When a place exists as node tagged a city, but also relation (same name and/or linked) tagged a village it might return it as village. There's open issues e.g. with London boroughs, Paris Arrondissements and quarters. lists the place types and the right columns of the table have global counts. has a hierarchy of fields relevant for an address. is Nominatim's internal logic to assign field names.

I would use the components.yaml, look for city aliases and if empty in the Nominatim response move up the hierarchy (county, state...).

permanent link

answered 01 Mar '19, 17:04

mtmail's gravatar image

accept rate: 27%

Thank you for your reply, I really appreciated it. Can you tell me what is wrong with places like this ? As you can see the only reference for place is country! Why?

(02 Mar '19, 14:13) Andreanovenove

That might be an issue with the Nominatim logic. Can happen in remote areas (no addresses in 20+ km radius or such) but shouldn't happen in dense populated areas. Add &zoom=16 to the URL since you said you don't need housenumber level data. Even zoom=10 might work for you. The parameter is explained here

(02 Mar '19, 22:44) mtmail

It doesn't do the trick. I get "city" with default zoom (18) from here, but not with zoom 10. Besides, I get no city, at any zoom level, with other GPS coordinates, like this

(03 Mar '19, 16:40) Andreanovenove

OpenStreetMap doesn't have enough data for that area. There isn't even a street mapped yet.

(03 Mar '19, 17:12) mtmail

Ok, I see. What do you think about the first link? Giving different zoom level doesn't always do the trick. Sometimes is convenient to use default zoom because level 10 doesn't return any city field, other times is better to use other zoom level, like 10, to get the city because default level doesn't contains any city field. So, there isn't a rule that I can follow to retrieve always an address field that is city or similar (similar administrative level).

(03 Mar '19, 19:10) Andreanovenove

Berlin is one of cases with conflicting information. is tagged as both admin_level=2 (state) and place=city and that confused the reverse geocoding.

(03 Mar '19, 20:09) mtmail
showing 5 of 6 show 1 more comments

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text]( "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:


question asked: 01 Mar '19, 16:24

question was seen: 9,177 times

last updated: 03 Mar '19, 20:09

NOTICE: is no longer in use from 1st March 2024. Please use the OpenStreetMap Community Forum