How can we get a list of countries/stats/cities in the world using Google places API? Using either google api javascript library or google api web service interface.
2) Make another web-service call to https://maps.googleapis.com/maps/api/place/details/json?key=API_KEY&placeid=place_id_retrieved_in_step_1. This will return a JSON which contains address_components . Looping through the types to find locality and postal_code can give you the city name and postal code.
The documentation says that the Places API returns up to 20 results. It does not indicate that there is any way to change that limit. So, the short answer seems to be: You can't. Of course, you might be able to sort of fake it by doing queries for several locations, and then merging/de-duplicating the results.
I don't believe that's allowed under the license terms of the Google Places API.
Instead, I suggest using http://geonames.org. Their data is updated very frequently and is licensed under a Creative Commons attribution license: http://creativecommons.org/licenses/by/3.0/
For country names & stats, the file is located here: http://download.geonames.org/export/dump/countryInfo.txt
All available downloads are here: http://download.geonames.org/export/dump/
So, to get the list of all places within a country that you requested, just fetch the zip file with the 2-letter ISO country code. For example, to get all places within the United States, fetch this file: http://download.geonames.org/export/dump/US.zip
Once fetched, you further have to filter the list in order to only get the cities.
Alternatively, if you're ok with just cities with population > 1000, use this file: http://download.geonames.org/export/dump/cities1000.zip
In fact, I recommend the 2nd approach, because all cities can be a very big list.
For more info and a list of all the files available: http://download.geonames.org/export/dump/readme.txt
Good luck on your project!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With