-
Notifications
You must be signed in to change notification settings - Fork 1
/
locator.py
57 lines (41 loc) · 1.46 KB
/
locator.py
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import urllib2
import json
<<<<<<< HEAD
def getCoordinates(d):
url = "http://maps.googleapis.com/maps/api/geocode/json?address=%s&sensor=false"%(d.replace(" ","+"))
=======
def getCoordinates(b):
url = "http://maps.googleapis.com/maps/api/geocode/json?address=%s&sensor=false"%(b.replace(" ","+"))
>>>>>>> master
result = urllib2.urlopen(url)
a = {}
try:
g = json.loads(result.read())["results"][0]
a["borough"] = g["address_components"][3]["long_name"]
a["neighborhood"] = str(b.split(",")[0])
a["lat"] = g["geometry"]["location"]["lat"]
a["long"] = g["geometry"]["location"]["long"]
except:
return -1;
return a
<<<<<<< HEAD
def getDirections(e,f):
url = "http://maps.googleapis.com/maps/api/directions/json?origin=%s&destination=%s&sensor=false"%(e.replace(" "," "),f.replace(" "," "))
=======
def getDirections(e):
url = "http://maps.googleapis.com/maps/api/directions/json?origin=%s&destination=%s&sensor=false"%(e.replace(" "," "))
request = urllib2.Request(url, headers = {'User-Agent': "Firefox"})
>>>>>>> master
result = urllib2.urlopen(url);
r = {}
try:
k = json.loads(result.read())["results"][0]
r["how_to_get_there"]=k["directions"][3]["routes"]
except:
return -1
return r
<<<<<<< HEAD
if __name__ == "__main__":
print getDirections("Upper East Side","Upper West Side")
=======
>>>>>>> master