Created
January 6, 2016 09:22
-
-
Save ppsreejith/b9007b0ad1ae6c1c2b1e to your computer and use it in GitHub Desktop.
Calculating distance for csv file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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