Reputation: 11
I'm trying to build a distribution app, I'm using googlemaps module and want to make a distance Matrix to calculate the closest destinations from a stable point on the map.
I'm using gmaps.distance_matrix
but after the 3 loops I'm getting the title error.
From other stackover articles already I tried use time.sleep()
but doesn't seems working!
The first 3 results are fine but after I get an error! If I'm not explaining something fine, let me know please!
import xlrd
import googlemaps
import collections
import time
loc=r'C:\Users\spyro\Desktop\files\Hotels.xlsx'
wb=xlrd.open_workbook(loc)
sheet = wb.sheet_by_index(0)
names=[]
address=[]
info={}
for i in range(sheet.ncols):
if (sheet.cell_value(0,i)=="Name") :
for k in range(sheet.nrows):
names.append(sheet.cell_value(k,i))
if (sheet.cell_value(0,i)=="Address"):
for k in range(sheet.nrows):
address.append(sheet.cell_value(k,i))
for n,a in zip(names,address):
info[n]=a
gmaps= googlemaps.Client(key="My key")
address="1062 Budapest, Andrássy út 53."
distances=collections.deque()
for i,n in info.items():
try:
print(n)
dist=gmaps.distance_matrix(address,n)["rows"][0]["elements"][0]
except Exception as e:
time.sleep(10)
dist=gmaps.distance_matrix(address,n)["rows"][0]["elements"][0]
Upvotes: 0
Views: 1042