Created
November 20, 2020 23:05
-
-
Save thisismattmiller/d01a8f1da462293f0aa31aac27e56f55 to your computer and use it in GitHub Desktop.
Code for Google Place API Demo: https://youtu.be/kgWaSZU0Um8
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
import requests | |
import json | |
import time | |
key = 'YOURKEYHERE' | |
url = 'https://maps.googleapis.com/maps/api/place/nearbysearch/json' | |
all_data = {} | |
search_lat_long = ['40.752933731021514, -73.98547317732873','40.75036387669075, -73.98316281312741'] | |
for coords in search_lat_long: | |
params = { | |
'key' : key, | |
'location' : coords, | |
'fields' : 'name,business_status,formatted_address,geometry,types,place_id', | |
'radius' : '500', | |
'type' : 'restaurant' | |
} | |
r = requests.get(url, params=params) | |
data = json.loads(r.text) | |
for restaurant in data['results']: | |
all_data[restaurant['place_id']] = restaurant | |
if 'next_page_token' in data: | |
time.sleep(5) | |
print('---------') | |
new_params = { | |
'key' : key, | |
'pagetoken' : data['next_page_token'] | |
} | |
r = requests.get(url, params=new_params) | |
data = json.loads(r.text) | |
for restaurant in data['results']: | |
all_data[restaurant['place_id']] = restaurant | |
if 'next_page_token' in data: | |
time.sleep(5) | |
print('---------') | |
new_params = { | |
'key' : key, | |
'pagetoken' : data['next_page_token'] | |
} | |
r = requests.get(url, params=new_params) | |
data = json.loads(r.text) | |
for restaurant in data['results']: | |
all_data[restaurant['place_id']] = restaurant | |
json.dump(all_data,open('places.json','w'),indent=2) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment