Search code examples
mongodbgeolocationdatabase

need a list for all countries with their states and cities including latitude and longitude


I am creating an App which needs data for countries, states and cities which is available at lots of places but here for some reason I need to know the latitude and longitude of each country including its state and city. From which one source can I find all these? I need to store this data in mongoDb.

I tried downloading allCountries.zip file from here GeoNames but I found that data is not in proper tsv format and it's very complicated to get the expected output data from here.

Is there anything else from which I can get the desired result?

Please help if anyone knows

Thanks a lot in advance :)


Solution

  • There is a webservice provided by geoNames which gives all the information about countries, states and cities.

    http://ws.geonames.org/childrenJSON?geonameId=8505026&username=demo
    

    this is an API which gives children i.e if you provide countries geonameId then it will give its states. If you provide states geonameId it will give its cities.

    So in that way we can have all the information about countries states and cities. To get all geonameId of countries for that they have provided another API

    http://api.geonames.org/countryInfoCSV?username=demo
    

    There is just one thing we should keep in mind that for username we have to create an account and whose credit limit is approx 2000 per day. So if we want to hit the API more than 2000 a day we have to create another account :)

    Pretty good thing and very useful thing provided by geoNames