GeocoderServiceError for geophysics

When I use geophysics to calculate the distances between two addresses based on their longitude and latitude, it works fine on separate data pairs. 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 the 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 the value of GeocoderServiceError (message) geo.exc.GeocoderServiceError: urlopen error [Errno 65] There is no route to the host

Do you know how I can avoid this problem?

My code is simple: (there are many data pairs for entering data for this)

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
+4
2
def get_level1_locations(lat_lng):
    elems = lat_lng.split(',')
    url = "http://maps.googleapis.com/maps/api/geocode/json?"
    url += "latlng=%s,%s&sensor=false" % (float(elems[0]), float(elems[1]))
    v = urlopen(url).read()
    j = json.loads(v)
    if len(j['results'])>0:
      components = j['results'][0]['address_components']
      location_list=[]
      for c in components:
          if "locality" in c['types']:
            location_list.append(c['long_name'])
          if "administrative_area_level_1" in c['types']:
            location_list.append(c['long_name'])
          if "country" in c['types']:
            location_list.append(c['long_name'])
      location = ', '.join(filter(None, location_list))
      return location
    return ''
+2

API- google map 2016 , (2017-08-30), , . ! , , . https://chrisalbon.com/python/geocoding_and_reverse_geocoding.html

0

Source: https://habr.com/ru/post/1627538/


All Articles