Created
December 15, 2019 21:30
-
-
Save Perishleaf/9bcc974be61cd59adedcac04590e75af to your computer and use it in GitHub Desktop.
Get nearby venues using Foursquare API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def getNearbyVenues(names, latitudes, longitudes, radius=500, LIMIT = 100): | |
venues_list=[] | |
for name, lat, lng in zip(names, latitudes, longitudes): | |
print(name) | |
# create the API request URL | |
url = 'https://api.foursquare.com/v2/venues/explore?&client_id={}&client_secret={}&v={}&ll={},{}&radius={}&limit={}'.format( | |
CLIENT_ID, | |
CLIENT_SECRET, | |
VERSION, | |
lat, | |
lng, | |
radius, | |
LIMIT) | |
# make the GET request | |
results = requests.get(url).json()["response"]['groups'][0]['items'] | |
# return only relevant information for each nearby venue | |
venues_list.append([( | |
name, | |
lat, | |
lng, | |
v['venue']['name'], | |
v['venue']['location']['lat'], | |
v['venue']['location']['lng'], | |
v['venue']['categories'][0]['name']) for v in results]) | |
nearby_venues = pd.DataFrame([item for venue_list in venues_list for item in venue_list]) | |
nearby_venues.columns = ['Suburb', | |
'Suburb Latitude', | |
'Suburb Longitude', | |
'Venue', | |
'Venue Latitude', | |
'Venue Longitude', | |
'Venue Category'] | |
return(nearby_venues) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment