51

I want to make service with API that give some info about a city (in any country) by some id.

What I should choose as id for cities? Does there exist an ISO standard for city identification? If so, where I can get a list of city ids?

DwB
  • 37,124
  • 11
  • 56
  • 82
petRUShka
  • 9,812
  • 12
  • 61
  • 95
  • Offhand the only city identifier system I know of are airport three-letter codes, which'd of course apply only to cities that have an airport. – Marc B Aug 15 '11 at 15:29
  • I'm guessing you want something like postal codes. And I think you're out of luck: http://en.wikipedia.org/wiki/Postal_code#Country_code_prefixes – Zecc Aug 15 '11 at 15:32
  • I'd suggest you use a numerical id based on latitude and longitude, by the way. Perhaps add a couple of letters from its name for readability. – Zecc Aug 15 '11 at 15:44
  • I am not aware of ISO codes for cities, although I just found in documentation for an airline API: *“Flight origin. It can be: City ISO 3 letter code, Airport IATA 3 letter code. If the received code is not found it will be considered an airport code. We prefer city, due to Amadeus works with cities.”* My suspicion is that by city codes they mean [IATA metropolitan area codes](http://wikitravel.org/en/Metropolitan_Area_Airport_Codes). – feklee Dec 15 '13 at 16:22
  • This question is wayyy off topic. Try opendata.stackexchange.com – Evan Carroll Dec 26 '18 at 21:32

5 Answers5

45

There is an ISO standard for Country code, but none (that I can find) for city code. There is, however; a United Nations Economic Commission for Europe United Nations Code for Trade and Transport Locations system of city identification UN/LOCODE.

Edit: Lined out the wrong name, added the slash to the UN/LOCODE name.

DwB
  • 37,124
  • 11
  • 56
  • 82
  • 4
    It is not United Nations but "United Nations Economic Commission for Europe". Database is incomplete. I tested Brazil. Brazil have 5570 cities and this db have only 2374. – macm Nov 22 '16 at 10:04
16

I decided to use IATA codes for cities.

Rudey
  • 4,717
  • 4
  • 42
  • 84
petRUShka
  • 9,812
  • 12
  • 61
  • 95
  • petRUShka have you a data base or api to associate IATA and cities? Sorry, I know that some time has passed, but I need that information. – David Jun 16 '14 at 13:35
  • 1
    @David, If I remember it right, I used this databases: http://openflights.org/data.html – petRUShka Jun 16 '14 at 18:16
  • 1
    what if there're 2 or more airports in the city? how would encode Moscow which has 3 airports? – Incerteza Oct 06 '14 at 13:51
  • @AlexanderSupertramp, there are separate identification codes for cities. In Moscow case it is MOW or "Moscow-MOW (MOW), Russia" according to http://openflights.org/html/apsearch – petRUShka Oct 06 '14 at 16:04
  • @petRUShka, sorry, I don't understand. Why is it Moscow-MOW (MOW) for Moscow and not Moscow-Vnukovo (VKO)? – Incerteza Oct 06 '14 at 16:36
  • what would you use for Shanghai? Why exactly that one (whatever you choose)? – Incerteza Oct 06 '14 at 16:37
  • 1
    IATA codes are very helpful for medium-large cities, but for situations dealing with smaller cities (without airports) one will need an alternative identifier. – Cato Minor Mar 30 '16 at 18:13
  • 3
    @アレックス Regarding cities with multiple airports, it should be noted that IATA Metropolitan Area Airport Codes exist for cities with multiple mainstream airports. http://wikitravel.org/en/Metropolitan_Area_Airport_Codes – Cato Minor Mar 30 '16 at 18:27
4

In addition to UNLOCODE, there is also the GeoNames database with its own numeric IDs.

This is probably only better than UNLOCODES if you already need to use the information in the GeoNames database or would prefer an integer-based ID system.

Cato Minor
  • 2,992
  • 3
  • 29
  • 42
3

For Europe there are also the NUTS codes. It goes into different levels of detail, depending on the country. For some countries like Germany you get the code for cities while for other countries like Spain you get only regions.

Germany's example: https://en.wikipedia.org/wiki/NUTS_of_Germany#Local_administrative_units

You can find the link to each country here: https://en.wikipedia.org/wiki/Category:Nomenclature_of_Territorial_Units_for_Statistics

J0ANMM
  • 7,849
  • 10
  • 56
  • 90
-3

You may use ISO 3166-2 standarts: http://en.wikipedia.org/wiki/ISO_3166-2

fkucuk
  • 631
  • 1
  • 9
  • 21