Build your free Distance Matrix API deployed on the cloud
In this Article, we will create a free, easy-to-implement and customizable (and a bit slow :D) Distance Matrix API using Flask with a Selenium Bot deployed on Heroku
Before starting to read this part, please forget everything you know about how to put in production a fast, efficient and stable code ensuring quick response with limited resources. This will be simple, quick and dirty, with no intention to be a scalable solution. The performance will be way lower than if you directly query the official Google API — but here it’s free :)
- Build a Selenium Bot that will query the distance from City A to City B in Google Maps Website
- Set up your Flask API that will receive the request and return a distance
- Deploy your code on Heroku
This repository code is ready to be deployed on Heroku:
pip3 install -r requirements.txt
Go to settings > Add Buildpack
Enter Two Links
https://github.com/heroku/heroku-buildpack-google-chrome
https://github.com/heroku/heroku-buildpack-chromedriver
CHROMEDRIVER_PATH: /app/.chromedriver/bin/chromedriver
GOOGLE_CHROME_BIN: /app/.apt/usr/bin/google-chrome
From: Paris, France
To: Marseille, France
http://xxx-xxx.herokuapp.com/distance/Paris,France/Marseille,France (replace xxx-xxx by your Heroku app name)
{“distance”:”775 km”}
Senior Supply Chain Engineer with an international experience working on Logistics and Transportation operations.
Have a look at my portfolio: Data Science for Supply Chain Portfolio
For consulting or advising on analytics and sustainable supply chain transformation, feel free to contact me via Logigreen Consulting
Data Science for Warehousing📦, Transportation 🚚 and Demand Forecasting 📈