Skip to content
Permalink
master
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
#Made by Andris Jansons
from googleplaces import GooglePlaces, types # 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 # If atleast one place is found
radius_int = radius_int + 100 # If not - increase radius
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() # An initializer for what's next
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 because we only need the first place
except:
placeName = None
placeAddress = None
placeWebsite = None
placePhone = None
finally:
return placeName, placeAddress, placeWebsite, placePhone