Route optimization is critical for any business that needs a cost effective way to deliver goods and services to their customers. If you are looking for an easy way to integrate route planning into your own software, the fastest solution is to sign up with a route optimization API (Application Programming Interface) provider like Routific, Graphhopper or Elastic Route (new). If you are interested in building your own, read on!

Part 1: Build your Own Route Optimization API with Google Maps
Part 2: Creating a Route with the Google Maps Directions API
Part 3: Optimizing a Route with the Google Maps Directions API
Part 4: Route Optimization Web Service Basics
Part 5: Let's Build a Route Optimization Web Service
Part 6: Putting it All Together - Testing your Route Optimization API

As always, all code used in this tutorial is available under a permissive MIT license on our Github repository, and you are free to use it in part or in whole for your own projects.

What is Route Optimization?

The term route optimization is widely used to refer to two different, but closely related things.

NOT: Driving directions - How to get from locations A to B in the fastest way possible.

The shortest route between two points A and B

HOT: Optimal route - You need to visit locations A, B, C and D in any order, in the fastest way possible - in the example below the optimal route goes A, C, D and B. This optimization is an application of the traveling salesperson problem. With Google, travel time is the primary factor which is optimized, but other factors such as distance, number of turns and many more may be taken into account when deciding which route is the most efficient.

The shortest route through points A, B, C and D

What we are Going To Build

We are going to build a route optimization web service on top of the Google Maps Directions API . The web service essentially works like a wrapper that allows data to be sent and received in json format making it easy to humans to read and machines to parse. We'll also build some extra features like authentication (client token security) and persistence (to retrieve your data using a job id) to give you a feel for how production web services are run.

API request made to our route optimization web service

At the end of this tutorial, you are going to be able to send the API a list of visits to be served by your fleet (limited to a single driver - for now) and get back the same list, but in route optimized order. This list can easily be displayed on a map or printed out and given to your driver.

Next: Part 2: Creating a Route with the Google Maps Directions API