Use case: I am trying to extract the latitide and longitude of addresses that I have collected from a website using python geocoder package.
Problem: Whenever I execute the given code, I keep getting the GeoCodeError.
Traceback (most recent call last):
File "C:/Users/Ashish/PycharmProjects/Petrogeocode.py", line 13, in <module>
address=Geocoder.geocode(addr)
File "C:\Users\Ashish\AppData\Roaming\Python\Python27\site- packages\pygeocoder.py", line 129, in geocode
return GeocoderResult(Geocoder.get_data(params=params))
File "C:\Users\Ashish\AppData\Roaming\Python\Python27\site- packages\pygeocoder.py", line 212, in get_data
raise GeocoderError(response_json['status'], response.url)
pygeolib.GeocoderError: Error ZERO_RESULTS
Query: https://maps.google.com/maps/api/geocode/json?language=®ion=&bounds=&components=&address=lot+1190%2C+mukim+bukit+tinggi+kepala+batas&sensor=false
Process finished with exit code 1
I searched SO for any possible solution, the closest I got was here but even if i remove the Zip code from the addresses, I still get the same error message.
The code is as follows
__author__ = 'Ashish'
from pygeocoder import Geocoder
from pygeolib import GeocoderError
bad_addr=open('bad_addr.txt','w')
good_addr=open('good_addr.txt','w')
with open('sample.txt') as f:
addrlist=f.read().splitlines()
for addr in addrlist:
address=Geocoder.geocode(addr) # read the first address in the list
try:
address=Geocoder.geocode(' '.join(addr)) # try to geocode it
if not address.valid_address:
bad_addr.write(str(address)) # if the address is not valid then write it to a file called bad_addr.txt
bad_addr.write(str(address.coordinates)) # Also write the coordinates if found
bad_addr.write("\n")
else:
good_addr.write(str(address)) # if the address is valid then write it to a file called good_addr.txt
good_addr.write(str(address.coordinates))
good_addr.write("\n")
# continue
except GeocoderError:
print "The address: ",addr," could not be geocoded" # catch the bad address exception thrown
bad_addr.close() # close the file
good_addr.close() # close the file
f.close()
the sample.txt file has addresses like given below
34 jalan nilam 1/1, tmn perindustrian teknelogi tinggi subang
no.82, jalan enau 15, taman teratai, kangkar pulai
lot 1190, mukim bukit tinggi kepala batas
no.16 jalan tampoi 7/1 kawasan perindustrian tampoi johor bahru
no. 187, jalan skudai, batu 4 1/2, johor bahru
75 jalan tuanku antah, seremban, negeri sembilan
10, 10a, persiaran datoh (off jalan lahat), ipoh, perak
Please suggest what can I do in my code to solve this problem. Thank you