Skip to content

Instantly share code, notes, and snippets.

@ppsreejith
Created January 6, 2016 09:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ppsreejith/b9007b0ad1ae6c1c2b1e to your computer and use it in GitHub Desktop.
Save ppsreejith/b9007b0ad1ae6c1c2b1e to your computer and use it in GitHub Desktop.
Calculating distance for csv file
import googlemaps
import csv
gmaps = googlemaps.Client('YOUR_API_KEY_HERE')
with open('NAME_OF_FILE.csv') as info:
read = csv.reader(info)
ans = []
for row in read:
ans.append(row[0] + ", Hong Kong")
start = 0 #replace this with starting value
for i in range(start, 450, 10):
for row in gmaps.distance_matrix(ans[i:i+10], ["#25 Man Fuk Road, Hong Kong"]*len(ans[i:i+10]), mode="driving")['rows']:
try:
print ans[start] + " - " + row['elements'][0]['duration']['text']
except:
print ans[start] + " - " + str(row['elements'][0])
start += 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment