When I am using geopy to calculate the distances between 2 addresses based on their longitude and the latitude, it works fine on individual pair of data. But when there is more data, it always gives me this error:
File "/Library/Python/2.7/site-packages/geopy/geocoders/osm.py", line 193, in geocode self._call_geocoder(url, timeout=timeout), exactly_one File "/Library/Python/2.7/site-packages/geopy/geocoders/base.py", line 171, in _call_geocoder raise GeocoderServiceError(message) geopy.exc.GeocoderServiceError: urlopen error [Errno 65] No route to host
Do you know how can I avoid this problem?
My code is simple: (The data input for this has many pairs of data)
from geopy.geocoders import Nominatim
from geopy.distance import vincenty
def calculate_distance(add1, add2):
geolocator = Nominatim()
location1 = geolocator.geocode(add1)
al1 = (location1.latitude, location1.longitude)
location2 = geolocator.geocode(add2)
al2 = (location2.latitude, location2.longitude)
distce = vincenty(al1, al2).miles
return distce