Optimizing Multi-Destination Routes with Google Maps and a Chrome Extension

Finding the best route between multiple destinations in Google Maps or other tools can be frustrating. I have created a bespoke Chromium browser extension to help calculate a relatively optimal multi-destination travel route. Usage: Install the extension, navigate to https://maps.google.com, and use the tool.


Table of Contents


Introduction

This will be a short blog article on my custom Chrome extension (which works with Chromium-based browsers) for optimizing multi-destination routes. This was a personal project that hopefully will help others as there don’t seem to be many free options for easy, automated multi-destination routing.

Google Maps Route Optimizer Results

Use Cases

My original use case for needing an optimized route came this Halloween; I wanted to collect a list of all local addresses with the best Halloween displays and route an optimal route to see them all. While I didn’t have this tool, I manually routed a few houses I found in a blog post and it was a very enjoyable experience for the family, some houses were incredible! Unfortunately, the manual routing was a pain - which is why I’m very excited to use this tool to route the best Christmas displays in our area this year!

However, this will work for most lists where the locations aren’t too far apart (distant locations = long Google Maps load times).

Some example use cases to create routes for:

  • (Halloween / Christmas / Holiday / etc.) Decorations
  • Parks
  • Landmarks
  • Road Trips
  • Delivery routes
  • Blogs & articles with addresses/destinations to visit
  • Other custom (business | personal) use cases

Example Use case: Routing Landmarks in Detroit

Below is a high-level methodology for collecting addresses from a blog post using JavaScript. Manual copy/paste would have worked equally well, but this technique may be useful for larger lists.

Collecting Addresses

I’ve opted to route between some landmarks in Detroit from this article: 25 of Detroit’s most Instagram-worthy landmarks.

The below image is a high-level overview of how I used JavaScript to parse the page and append some more specific location data “, Detroit, MI, USA” to help Google Maps identify the specific location.

page with landmarks

  • (1) & (2) are the format of the original page
  • (3) is a single line of JavaScript I wrote to extract all locations and added some more specific locations to help Google Maps (added ‘, Detroit, MI, USA’ to each location).

      // JS oneliner to extract all the addresses
      console.log(Array.from(document.querySelectorAll('b')).map(ele=>{return ele.innerText + ', Detroit, MI, USA' }).join('\n'))
    
  • (4) The output

    Here is a subset of the addresses

      Belle Isle Aquarium, Detroit, MI, USA
      Michigan Central Station, Detroit, MI, USA
      The RiverWalk, Detroit, MI, USA
      Motown Museum, Detroit, MI, USA
      Heidelberg Project, Detroit, MI, USA
      The Fisher Building, Detroit, MI, USA
      ...
    

Optimizing the Route

Anyone that has used Google maps to optimize 31 routes will tell you this is unfeasible (unless I’m missing something). My goal here, however, is to be able to export the results of my optimizations to google maps so I can send a link to my phone which opens the optimized route.

Option 1: Free Solution

1.a) Mapquest

Mapquest does offer a free tool: https://www.mapquest.com/routeplanner/copy-paste

It’s quite good but still has major limitations. You can only route 26 addresses at a time, it’s all manual moving of each node (address), and once you finally get a route there is no easy way to send it to Google Maps. Originally I planned to inject code into this page to make the export process easier, but I ended up injecting straight into Google Maps (more on that soon).

1.b) RouteXL

RouteXL also offers a free tool: https://www.routexl.com

The first time I tried to use it I hit a warning that said I needed to upgrade (more than 20 stops).

page with landmarks

Source: https://www.routexl.com/blog/pricing

Option 2: Paid Solution

Other paid solutions cost $100/yr or more. Needless to say, I’m not interested in paying a subscription for this functionality, but I will add the information here for completeness.

Some alternatives can be found here, they are quite fancy and would be more appropriate in a corporate environment: https://www.badgermapping.com/blog/multi-stop-route-planner/. They also offer a lot more features if you are willing to spend some $$$.

Option 3: Custom Solution!

Note: Google still needs to calculate distances so long routes with several stops will take a long time to process. Also, this extension may break as https://google.com/maps is updated.

The reason you are reading this blog post is that I rolled my solution for funsies.

I have made a quick YouTube video to show its usage.

“Go” - opens Google Maps with a route, in the current order. “Optimize & Go” - finds the optimal route based on time and opens a Google Maps route with that optimal order

There is a feature to free the first X addresses where optimization is not calculated, thus routes can be a bit more customized.

Tips, Tricks & Known Issues

Please be aware there are some quarks with this solution.

  • This project is open source! A savvy user can update my code for their use case. (Downloads & Links)
  • If you encounter a bug, try refreshing the page and starting over.
  • I have noticed that perhaps keeping the number of locations below 26 is ideal. Even if the locations are close, Google Maps doesn’t seem to want to show too many at once.
  • I have not throttled requests much, they are done in batches for each destination calculation (e.g. when optimizing the next stop for a route that has 14 unfinished stops, it will send 14 parallel requests to calculate the optimal next stop.)
  • “Optimal” routes do not take into account clustering or any other advanced techniques.
  • Ambiguous addresses will be interpreted as if searching in the Google Maps search bar (local locations are prioritized) and resolved to a local address (probably the wrong one) - double check your route when complete to ensure that all addresses are accurate!

Conclusion

Overall, this was a fun, mini-project that I plan to leverage for as long as I can (until it breaks from a Google Maps update). Hopefully, it helps someone else as well. Cheers!





Comments