3

A system I'm developing is using ISO 3166-2 codes / names to serve as a dropdown for users to pick their state / province / country / etc. However, as I recently learned, some countries, like Great Britain, have gone a bit overboard with their subdivisions, making it a bit hard for some users to pick the correct one for themselves. For example, instead of having "Greater London", you have to specify the specific borough inside of London, etc.

This made me have an idea that if I took the postal code someone put in their address field I could pre-populate the proper area and not have to ask the user for it, saving some confusion.

I was wondering - is there some list or service that correlates a postal code to an ISO 3166-2 code, ideally on a global scale? I know it's possible to find such data sets for the US or UK individually, but I haven't found anything on a global scale...

2

Geonames has postal codes but they're per city not per ADM1.

Eg the city https://www.geonames.org/728378/pazardzhik.html shows post=4400, and in Hierarchy shows its parent ADM1 https://www.geonames.org/728379/pazardzhik.html.

This is available in structured data, so you need to find all populated places (featureClass=P) per ADM1 and collect their postal codes.

Then you need to find ISO_3166-2 codes of ADM1 from eg https://en.wikipedia.org/wiki/ISO_3166-2:BG and link them to Geonames.


Actually it's best to use Wikidata, where this info is connected:

Now you need to learn some SPARQL to tie all this up

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.