-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgeocode.py
24 lines (18 loc) · 885 Bytes
/
geocode.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import csv
from pygeocoder import Geocoder, GeocoderError
# Should have a CSV file with headers, the minimun headers should be:
# 'Street' 'City' 'State' 'Zip Code'
geocoder = Geocoder()
# geocoder = Geocoder(api_key='MY_SIMPLE_API_KEY') # if you have an api key, use it here...
# CSV File location
file_location = "Locations to Visit.csv"
with open( file_location, "rb" ) as theFile:
reader = csv.DictReader( theFile )
print 'Longitude, Latitude'
for line in reader:
# line is { 'workers': 'w0', 'constant': 7.334, 'age': -1.406, ... }
# e.g. print( line[ 'workers' ] ) yields 'w0'
# Headers are used here.
address = line['Street'] + ", " + line['City'] + ", " + line['State'] + " " + line['Zip Code']
results = geocoder.geocode(address)
print str(results[0].coordinates[1]) + ', ' + str(results[0].coordinates[0])