Skip to content

Instantly share code, notes, and snippets.

@chribsen
Last active March 21, 2016 13:23
Show Gist options
  • Save chribsen/b70d9ef314acc7949799 to your computer and use it in GitHub Desktop.
Save chribsen/b70d9ef314acc7949799 to your computer and use it in GitHub Desktop.
Receives places in 10km vicinity to Roskilde Festival from Google and stores them into a JSON file.
import requests, json
import time
# Places token
token = '<my_token>'
params = {'key': token,
'location': ','.join([str(55.622534),str(12.080729)]),
'radius': 10000}
data = []
r = requests.get('https://maps.googleapis.com/maps/api/place/nearbysearch/json',params=params)
response = r.json()
data += response['results']
while response.get('next_page_token'):
params['pagetoken'] = response['next_page_token']
time.sleep(2)
r = requests.get('https://maps.googleapis.com/maps/api/place/nearbysearch/json', params=params)
print(r.url)
response = r.json()
print(json.dumps(response, indent=2))
data += response['results']
print('places: ' + str(len(data)))
f = open('places_10km.json', 'w')
f.write(json.dumps(data, indent=2))
f.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment