Is there any API that lists states and cities?

13

I've been looking for some json API that lists the states of a certain country, or cities of a certain state, I've looked for this functionality through various Google Maps APIs but I did not find anything that was exactly for that.

I do not want to use a DB with a list of states and cities because I believe it lacks flexibility and is quite heavy.

Note: I need to create a combobox of countries, states and cities, but I can use a list of countries directly from the database without any problem, but if there is an API that makes this list available, p>

Is there a good option?

    
asked by anonymous 25.07.2015 / 17:18

1 answer

20

You can use the geonames.org service.

This example page shows the calls to the service:

link

The specific function you want to use is Children , which returns collections of child entities of a given GeoNameID - countries of a continent, states of a country, cities of a state and so on.

The above example makes the following calls:

  • Gets a list of continents

    link

  • After selecting South America ( GeoNameID 6255150), you get the list of countries

    link

  • After selecting Brazil (GeoNameID 3469034), you get the list of states

    link

  • The end result is a list similar to the example below:

    {
    "totalResultsCount":27,
    "geonames":[
        {
        "geonameId":3665474,
        "toponymName":"Acre"
        },
        {
        "geonameId":3408096,
        "toponymName":"Alagoas"
        },
        {
        "geonameId":3407762,
        "toponymName":"Amapá"
        },
        [...]
    
        
    25.07.2015 / 18:37