Python & Google Places API | Want to get all Restaurants at a specific postion
Solution 1
It'll be better if you drop the keyword
parameter, types
already searches for restaurants.
Bear in mind the Places API (as other Google Maps APIs) is not a database, it will not return all results that match. Actually returns only 20, and you can get an extra 40 or so, but that's all.
If I'm reading the GooglePlaces correctly, your code will send an API request such like:
If you just drop the keyword
parameter, it'll be like:
The difference is subtle: keyword=Restaurants
will make the API match results that have the word "Restaurants" in their name, address, etc. Some of these may not be restaurants (and will be discarded), while some actual restaurants may not have the word "Restaurants" in them.
Solution 2
Try to change city value by latitude and longitude and it's not necessary to put the keyword because you are specified that on Type try to put this code it's work for me :
query_result = google_places.nearby_search(
lat_lng={'lat': 46.1667, 'lng': -1.15},
radius=5000,
types=[types.TYPE_RESTAURANT] or [types.TYPE_CAFE] or [type.TYPE_BAR] or [type.TYPE_CASINO])
Sebastian Fischer
Updated on June 30, 2022Comments
-
Sebastian Fischer almost 2 years
I want to get all restaurants in London by using python 3.5 and the module
googleplaces
with the Google Places API. I read thegoogleplaces
documentation and searched here, but I don't get it. Here is my code so far:from googleplaces import GooglePlaces, types, lang API_KEY = 'XXXCODEXXX' google_places = GooglePlaces(API_KEY) query_result = google_places.nearby_search( location='London', keyword='Restaurants', radius=1000, types=[types.TYPE_RESTAURANT]) if query_result.has_attributions: print query_result.html_attributions for place in query_result.places: place.get_details() print place.rating
The code doesn't work. What can I do to get a list with all restaurants in this area?