Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retrieve a list of country names using Google places api

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.

like image 747
Yiling Avatar asked Jul 17 '15 11:07

Yiling


People also ask

How do I get my city name from places API?

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.

How can I get more than 20 results on Google Places API?

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.


1 Answers

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!

like image 60
yahermann Avatar answered Oct 09 '22 17:10

yahermann