1

我是编程和 python 的新手,所以请不要讨厌。我正在尝试构建一个程序,该程序将 Excel 表中的地址列表转换为列表,然后使用 google maps api 检索每个地址的距离和时间。到目前为止,我只能对一个地址进行硬编码。到目前为止,我唯一的问题是遍历 gmaps.directions() 参数。我很乐意帮助您如何做到这一点。所以最后我想要多次和距离来比较它们。谢谢

from googlemaps import GoogleMaps
import xlrd



gmaps = GoogleMaps('gmaps api')

wb = xlrd.open_workbook('addressbook.xlsx')
ws1 = wb.sheet_by_name('Sheet1')
ws2 = wb.sheet_by_name('Sheet2')
col1 = ws1.col_values(1)
col2 = ws2.col_values(1)



dirs = gmaps.directions(col1[0] ,col2[0])
time = dirs['Directions']['Duration']['seconds']
dist = dirs['Directions']['Distance']['meters']



print time 
print dist
4

1 回答 1

0

尝试尽可能地接近你已经拥有的东西:

from googlemaps import GoogleMaps
import xlrd



gmaps = GoogleMaps('gmaps api')

wb = xlrd.open_workbook('addressbook.xlsx')
ws1 = wb.sheet_by_name('Sheet1')
ws2 = wb.sheet_by_name('Sheet2')
col1 = ws1.col_values(1)
col2 = ws2.col_values(1)


for c1 in col1:
    for c2 in col2:
        dirs = gmaps.directions(c1 , c2)
        time = dirs['Directions']['Duration']['seconds']
        dist = dirs['Directions']['Distance']['meters']

        print time 
        print dist

(我不知道你对编程有多么陌生,但不管它看起来像一个教程都是为了)

于 2013-05-26T23:32:25.623 回答