5

I have a dataset with latitude and longitude coordinates, and I would like to get actual addresses for those. Since I'm using Geopy and Nominatim, I am limited to 1 request per second.

Although the examples I have seen to find a way around this involve using time.sleep(1) method, geopy has a RateLimiter class specifically for those purposes.

The only issue is that it doesn't seem to work on reverse geocoding for me, it keeps saying that the RateLimiter doesn't have an attribute reverse.

Am I doing something wrong?

from geopy.geocoders import Nominatim
from geopy.extra.rate_limiter import RateLimiter

geolocator = Nominatim(user_agent="application")

geocode = RateLimiter(geolocator, min_delay_seconds=1)

location = geocode.reverse((50.6539239, -120.3385242), language='en', exactly_one=True)

print location.raw

AttributeError: 'RateLimiter' object has no attribute 'reverse'
1

1 Answer 1

11

The correct usage of RateLimiter for reverse geocoding would be:

from geopy.geocoders import Nominatim
from geopy.extra.rate_limiter import RateLimiter

geolocator = Nominatim(user_agent="application")

reverse = RateLimiter(geolocator.reverse, min_delay_seconds=1)

location = reverse((50.6539239, -120.3385242), language='en', exactly_one=True)

print location.raw
1
  • works perfectly! Thank you @KostyaEsmukov Commented Aug 7, 2019 at 10:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.