This code supplements my lightning talk at DevFest Springfield 2019. I demonstrate how to use the Google Distance Matrix API to calculate the most convenient lunch location given a list of potential attendee addresses and a list of potential event locations.
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes.
This code requires Python 3
$ python -V
Python 3.7.0
This code also requires a Google Maps API key. Be sure to allow Google Distance Matrix API calls.
Cost: Be aware that calls to the Google Distance Matrix API cost $5 per 1K elements. Each origin/destination pair in your request is considered an element, so multiply the number of origins with the number of destinations to determine the number of elements in your API call. For example, an API call with 100 origins (potential lunch attendees) and 10 destinations (potential lunch event locations) would contain 1000 elements (100 x 10) and would cost $5.00 total.
Caveats: This sample code queries each element separately and caches the results to allow repeat analysis without incurring additional charges. Be sure to avoid caching invalid responses (e.g. errors). Be sure to manage cache expiration if you choose to cache API responses.
You must clone or download this repository, initialize a Python environment with dependencies, and populate your data files before you can run the demo scripts.
Clone the repository to your computer
git clone https://github.com/jason-klein/google-distance-matrix-api-example.git
Create virtual environment
python -m venv venv
Activate virtual environment
source ./venv/bin/activate
Install package requirements
pip install -r requirements.txt
Copy sample member data file OR download member data
cp members.dat.sample members.dat
# or
python members.py
Prune member data to remove PO Boxes and out of state addresses
./members-prune.sh
Copy sample event location data
cp events.dat.sample events.dat
Calculate distances from each member to potential event locations
python distance.py
Analyze pipe-delimited data file
cat distance.csv
This demo does not contain tests.
This demo is not intended for production.
- Python - The programming language used
- Google Maps - The maps platform used
Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.
This demo is not versioned
- Jason Klein - Initial work - jason-klein
See also the list of contributors who participated in this project.
This project is licensed under the MIT License - see the LICENSE.md file for details
- AITP of the Ozarks - Thank you for the opportunity to serve as your board President (2016-2017). This demo is based on code I wrote in early 2016 to calculate the average travel time to potential meeting locations after our chapter outgrew the meeting space at eFactory. This code determined that Hilton Garden Inn was the most convenient location for our 280 members. The chapter met at HGI for two years (2017-2018).
- Google DevFest Springfield - Thank you for the opportunity to speak at your event again this year.
- Mid-America Technology Alliance and Springfield Devs - Thank you to everyone involved in these organizations for doing their part to help make tech events like DevFest possible in the Springfield Missouri technology community.
- Logic Forte - Thank you for paying for the API costs related to producing this demo.