-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgoogle_api_example.py
More file actions
40 lines (35 loc) · 1.27 KB
/
google_api_example.py
File metadata and controls
40 lines (35 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
from access_keys import access_keys
import requests
class google_api(object):
def __init__(self):
self.key = access_keys.google_key
def generate_url(self, addresses):
base_url = 'https://maps.googleapis.com/maps/api/distancematrix/json?origins={0}W&destinations={1}&sensor=false&key={2}'
rows = '|'.join(addresses)
url = base_url.format(rows, rows, self.key)
return url
def get_distance_matrix(self, addresses):
url = self.generate_url(addresses)
resp = requests.get(url)
return resp.text
api = google_api()
addresses = ['37.524968,-122.2508315',
'37.520515,-122.257320',
'37.494497,-122.246788',
'37.563856,-122.249911',
'37.487424,-122.235715',
'37.547685,-122.298318',
'37.551216,-122.301655',
'37.524105,-122.252680',
'37.519722,-122.275186',
'37.545468,-122.272053',]
# '37.529040,-122.289248',
# '37.561070 -122.274370',
# '37.568597 -122.266075',
# ]
# print len(addresses)
import time
t1 = time.time()
text = api.get_distance_matrix(addresses)
# print text
print time.time() - t1