-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgrabcoords.py
50 lines (39 loc) · 1.29 KB
/
grabcoords.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
import csv
import sys
baseURL = 'http://maps.googleapis.com/maps/api/geocode/xml?sensor=false&address='
toGeocode = '7817+Baltimore National Pike+Frederick'
ConnectionString = baseURL + toGeocode
#download the file:
file = urllib2.urlopen(ConnectionString)
#convert to string:
data = file.read()
#close file because we dont need it anymore:
file.close()
#parse the xml you downloaded
dom = parseString(data)
#create empty list
doc = []
#loop through the first 8 xml tags and display
f = 0
for f in range(8):
xmlTag = dom.getElementsByTagName('short_name') [i].toxml()
#strip off the tag (<tag>data</tag> ---> data):
xmlData=xmlTag.replace('<short_name>','').replace('</short_name>','')
#encode each xmlTag element as ASCII to avoid unicode character
Data=xmlData.encode('ascii')
#append Data element to our list 'row'
doc.append(Data)
#rinse, repeat
f+= 1
#now we get the lat/lon (but we don't
#need to loop through like we did above)
a = 0
xmlLatTag = dom.getElementsByTagName('lat') [a].toxml()
xmlLat=xmlLatTag.replace('<lat>','').replace('</lat>','')
xmlLonTag = dom.getElementsByTagName('lng') [a].toxml()
xmlLon=xmlLonTag.replace('<lng>','').replace('</lng>','')
Lat=xmlLat.encode('ascii')
Lon=xmlLon.encode('ascii')
doc.append(Lat)
doc.append(Lon)
print doc