Center for Geographic Analysis Harvard University
Additional navigation

You are here

Batch Distance Calculation using Google Distance Matrix API

The python script is to batch calcualte the road distance (meters) and travel time (seconds) between paired locations (origin x/y and destination x/y) using Google Distance Matrix API.

This code uses Google Maps API for Work license that is shared campus-wide, which will ideally calculate: 

  • 625 elements per query
  • 1000 elements per 10 seconds
  • 100 000 elements per 24 hour period

Python 2.X or Python 3.X must be installed on the computer running the script. Please find the corresponding version of python to download. 

Note: The input file must be a tab-delimited text file without headers, and only has 5 fields in the following order: ID, origin Y (latitude), origin X (longitude), destination Y (latitude), and destination X (longitude).

The software is free to download, but you will need to login with your HUID/HarvardKey here: Software Access page (click) to get credentials for downloading from the Downlad Link section below.