Connecting Google Maps and Google Sheets to Solve the Traveling-Salesman Problem
Connecting Google Maps and Google Sheets can help us solve important and difficult problems. A typical problem is when we have a list of addresses in a Google spreadsheet, and we want to find the shortest possible route that visits each place exactly once. Finding the shortest route visiting a list of addresses is known as the Traveling-Salesman Problem.
How can we solve this problem without coding a complex algorithm? Keep reading!
Using Google Maps to solve the Traveling-Salesman Problem
We know that Google Maps is capable of calculating a solution to this classical optimization problem. The key question is how to use Google Maps and Google Sheets to solve the Traveling-Salesperson Problem? Google Sheets doesn’t offer any predefined function callable from a spreadsheet cell to compute the solution. The only option available is to open the Google Apps Script Editor, write our own JavaScript (Google Apps Script, to be specific) function, and call it from the spreadsheet. Luckily, the JavaScript customized version used by Google Sheets already includes a reference to the Google Maps object, so our task will be relatively simple. We will not need to dig into Google Maps API or implement some complex authentication…