Last active
March 21, 2016 13:23
-
-
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.
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, 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