google maps api help

  • Thread starter Christopher Saunders
  • Start date
C

Christopher Saunders

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 [] ?
 
M

MRAB

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]))
 
C

Christopher Saunders

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!
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top