Reputation: 127
I'm learning geopy and am having trouble understanding the kind of argument that it accepts when returning address or longitude/latitude values.
I have a pandas series with address information I'm trying to get the lat/lon of each address. When geopy returned NoneType error, I thought it had to do with apartment/unit numbers in the addresses. I parsed those out, and the geopy code works for something like
from geopy.geocoders import Nominatim
geolocator = Nominatim()
location = geolocator.geocode("5301 Joyce Street Vancouver")
print((location.latitude, location.longitude))
but not:
from geopy.geocoders import Nominatim
geolocator = Nominatim()
location = geolocator.geocode("1926 4th Avenue West Vancouver")
print((location.latitude, location.longitude))
which returns this:
AttributeError Traceback (most recent call last)
<ipython-input-13-055d7e63348a> in <module>()
2 geolocator = Nominatim()
3 location = geolocator.geocode("1926 4th Avenue West Vancouver")
----> 4 print((location.latitude, location.longitude))
AttributeError: 'NoneType' object has no attribute 'latitude'
why is this the case?
Upvotes: 0
Views: 3606
Reputation: 424
I faced the same problem, the reason for the error ~ "NoneType object has no attribute 'latitude'" is because the geolocator() is not returning any location resulting variable "location" to be None
location = geolocator.geocode("5301 Joyce Street Vancouver") # returns None therefore,
location = None
Reason: This Happens because the required location might not be present in the geolocator() library. Solution: we can't solve this because the geolocator is not having the address of "5301 Joyce Street Vancouver".
Upvotes: 1