I'm trying my hands on reverse geocoding with python and the module geocoder
I built this script
#!/Users/admin/anaconda/bin/python
import geocoder
import unicodecsv
import logging
with open('locs2.csv', 'rb') as f:
reader = unicodecsv.DictReader(f, encoding='iso-8859-1')
for line in reader:
lat = line['lat']
lon = line['lon']
g = geocoder.google(['lat','lon'], method=reverse)
if g.ok:
g.postal
logging.info('Geocoding SUCCESS: ' + address)
else:
logging.warning('Geocoding ERROR: ' + address)
According to the doc here, we can do reverse. However, when I'm running the script , I have this error NameError: name 'reverse' is not defined
Why?
TIA
This is a sample from my file
lat, lon
48.7082,2.2797
48.7577,2.2188
47.8333,2.2500
48.9833,1.7333
47.9333,1.9181
46.2735,4.2586
**Edit **: I've amended the script a bit (see below) and I have this error
WARNING:root:Geocoding ERROR:
the amended script
#!/Users/admin/anaconda/bin/python
import geocoder
import unicodecsv
import logging
pcode=[]
lat=[]
lon=[]
with open('locs2.csv', 'rb') as f:
reader = unicodecsv.DictReader(f, encoding='iso-8859-1')
for line in reader:
lat = line['lat']
lon = line['lon']
g = geocoder.google([lat,lon], method='reverse')
if g.ok:
pcode.extend(g.postal)
logging.info('Geocoding SUCCESS: '+
str(lat)+','+str(lon)+','+str(pcode))
else:
logging.warning('Geocoding ERROR: ' + str(lat)+','+str(lon))
fields= 'lat', 'lon', 'pcode'
rows=zip(lat,lon,pcode)
with open('/Users/admin/python/myfile.csv', 'wb') as outfile:
w = unicodecsv.writer(outfile, encoding='iso-8859-1')
w.writerow(fields)
for i in rows:
w.writerow(i)