google maps api help

Discussion in 'Python' started by Christopher Saunders, Oct 20, 2011.

  1. 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 [] ?
     
    Christopher Saunders, Oct 20, 2011
    #1
    1. Advertisements

  2. Christopher Saunders

    MRAB Guest

    Try turning the lists into tuples:

    result = gmaps.directions(tuple(odList[0][2]), tuple(odList[1][2]))
     
    MRAB, Oct 20, 2011
    #2
    1. Advertisements

  3. Awesome, that worked!
     
    Christopher Saunders, Oct 20, 2011
    #3
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.