Skip to content
Permalink
1411aa100c
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
47 lines (38 sloc) 1.77 KB
from googleplaces import GooglePlaces, types, lang # You need to use googleplaces library
YOUR_API_KEY = 'AIzaSyDOIMYjnWeH8fgT5YaYfrjo4BzEqyHR6PM' #You get this from Google Console
google_places = GooglePlaces(YOUR_API_KEY)
def findPlace(location_str='Coventry University',keyword_str='Food'):
"""Finds the closest place to given location matching a specific keyword or maybe type later on"""
try:
placeName = ''
placeAddress = ''
placeWebsite = ''
placePhone = ''
radius_int = 50
while True:
query_result = google_places.nearby_search(
location=location_str,
keyword=keyword_str,
radius=radius_int )
#types=[types.TYPE_FOOD] if you need a specific type
if len(query_result.places)>0:
break
radius_int = radius_int + 100
if query_result.has_attributions:
print (query_result.html_attributions)
for place in query_result.places: #For each found place print details
place.get_details()
placeName = place.name
placeAddress = place.formatted_address
if not(place.website == None):
placeWebsite = place.website
if not(place.local_phone_number == None):
placePhone = place.local_phone_number
return placeName, placeAddress, placeWebsite, placePhone # Also works as a break statement
except:
placeName = None
placeAddress = None
placeWebsite = None
placePhone = None
finally:
return placeName, placeAddress, placeWebsite, placePhone