google maps api help

Christopher Saunders chris at 3fdev.com
Thu Oct 20 15:28:44 EDT 2011


On Oct 20, 1:02 pm, MRAB <pyt... at mrabarnett.plus.com> wrote:
> 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]))

Awesome, that worked!



More information about the Python-list mailing list