google maps api help

MRAB python at mrabarnett.plus.com
Thu Oct 20 15:02:50 EDT 2011


On 20/10/2011 19:39, Christopher Saunders wrote:
> I have an excel sheet with a bunch of info regarding the stops a
> delivery truck makes throughout the day.  I can successfully extract
> the information I need with xlrd.  This is the code I am using:
>
> book = xlrd.open_workbook(r'c:\xytest.xls')
> sheet= book.sheet_by_index(0)
> odList = []
>
> for i in range(1,6125):
>      cID = sheet.row(i)[0].value #Company ID
>      tID = sheet.row(i)[1].value #Truck ID
>      xyCoord = sheet.row_values(i,start_colx = 8,end_colx = 10 ) #long
> and lat
>      xyCoord.reverse() #reversed, so that lat,long is in correct format
>      odList.append([cID,tID,xyCoord])
>
>
> Printing odList give me this output where fields are
> [CompanyID,TruckID, Lat,Long] : [[5000020.0, 1.0, [35.779999,
> -78.115784]], [5000020.0, 1.0, [36.075812, -78.256766]], [5000020.0,
> 1.0, [35.779999, -78.115784]], [5000020.0, 2.0, [35.79528,
> -78.137549]], [5000020.0, 3.0, [35.79528, -78.137549]]
>
> I used list indices to grab the coordinates and query gmaps with:
>
> result = gmaps.directions(odList[0][2],odList[1][2])
> time = result['Directions']['Duration']['seconds']
> dist = result['Directions']['Distance']['meters']
>
> Unfortunately, gmaps does not understand [35.779999, -78.115784],
> [36.075812, -78.256766], gmaps does understand (35.779999, -78.115784),
> (36.075812, -78.256766).  Any ideas on how to get the query to send ()
> instead of [] ?

Try turning the lists into tuples:

result = gmaps.directions(tuple(odList[0][2]), tuple(odList[1][2]))



More information about the Python-list mailing list