Original question

I create an web application and I need to obtain the information contained in the question on the backend side of my application.

What I need the most is the automatic retrieval of information about the city based on the name of the country and the postal code. State is optional.

I would like to have free use in commercial use, but if there is no free solution to this question, what is the cheapest solution?

Do you know about such API?

If so, is the use of it related to any quantitative limits or legal restrictions?

Update:

I have in database information about country and postcode provided by users in form on my site. This may apply to the whole world. The names of countries are always correct and the postal code is not necessarily.

What do I want to receive?

If the postal code is incorrect for a given country, I want to receive information: the place does not exist and the state does not exist.

If the postal code is correct for the given country, but there is no administrative division into the state in this country, I want to get the name of the town that this postal code refers to and the information that the state does not exist (or the name of the country).

If the postal code is correct for a given country and there is an administrative division into the state in this country, I would like to receive the name of the location to which the zip code applies and the name of the state or province in which it is located.

By the name of the location I understand: the name of the village, town or town to which the postal code is assigned. If possible, I would not like to get district names here, but if it is problematic, they can be.

By state I understand the largest administrative unit on which the country is divided. It may be a state, a province, a region, an island name, etc. As far as possible, I would not like to receive the names of districts, communes, counties etc. in this place, but if it is problematic, it can be.

Examples:

{"countryName": "United States of America", "postalCode": "90201"}
    => {"locationName": "Los Angeles", "stateName": "California"}

{"countryName": "United Kingdom", "postalCode": "PH33 6DB"}
    => {"locationName": "Fort William", "stateName": "Scotland"}

{"countryName": "Poland", "postalCode": "11-230"}
    => {"locationName": "Biegonity", "stateName": "warmińsko-mazurskie"}

{"countryName": "Italy", "postalCode": "97019"}
    => {"locationName": "Vittoria, "stateName": "Sicilia"}

{"countryName": "Mongolia", "postalCode": "65193"} 
    => {"locationName": "Цэцэрлэг", "stateName": "Хангайн бүс"}

However, if it is a big problem to serve information from the whole world, maybe at least I can get information from some continents or countries (e.g. North America and Europe etc.).

What I took into account?

  • I do not have much experience in this matter, but from what I see most of the Geolocation API works in such a way that it works with geographic co-ordinates of the earth, but it's not my case at the moment.

  • I think that the Google Geocoding API could handle this task, because I can give the address (maybe even not full like in my case) and it can return a lot of information about the address from which I could extract something..., but I must have an account, and what prevents me from setting up this account is that this service is paid, and I would not like to pay additional costs if I do not have to.

  • Maybe also it would be a good idea to put own database with the right information, but where to get a reliable database for commercial use, which is free or not too expensive? Does GeoNames

I will be grateful for any suggestion or help.

up vote 2 down vote accepted

What about the nominatim service of the OpenStreetmap Project?

Searching for "USA" with Zip Code 90026 (West Los Angeles) yields:

https://nominatim.openstreetmap.org/search?q=USA+90026&addressdetails=1&format=json

[
  {
    "place_id": "200404602",
    "licence": "Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright",
    "boundingbox": [
      "34.073635833461",
      "34.073735833461",
      "-118.26462710011",
      "-118.2645271001"
    ],
    "lat": "34.0736858334611",
    "lon": "-118.264577100105",
    "display_name": "Los Angeles, California, 90026, USA",
    "class": "place",
    "type": "postcode",
    "importance": 0.44500000000000006,
    "address": {
      "city": "Los Angeles",
      "state": "California",
      "postcode": "90026",
      "country": "USA",
      "country_code": "us"
    }
  }
]

Germany 14482 also works properly.

I don't know the rate limits, but maybe there are API-offering companies that are generous.

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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