Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

Googlemaps_distance script error.

28 views
Skip to first unread message

Mitch Nienhuis

unread,
Mar 20, 2025, 4:20:53 PMMar 20
to Google Apps Script Community
I have a business spreadsheet that is tied to a Google Form so I can track my expenses and mileage. In that table, I have a separate column to auto-calculate the mileage based on the address entered into the Form. It was working fine up until last month but now, for some reason, it throws an error (No route found). Clearly, this is an error, since it worked fine last month and manually typing in the addresses in Google Maps returns a distance. I am wondering what changed to lead to this error? Script is below.

​/**
 * Calculate the distance between two
 * locations on Google Maps.
 *
 * =GOOGLEMAPS_DISTANCE("NY 10005", "Hoboken NJ", "walking")
 *
 * @param {String} origin The address of starting point
 * @param {String} destination The address of destination
 * @param {String} mode The mode of travel (driving, walking, bicycling or transit)
 * @return {String} The distance in miles
 * @customFunction
 */
const GOOGLEMAPS_DISTANCE = (origin, destination, mode) => {
  const { routes: [data] = [] } = Maps.newDirectionFinder()
    .setOrigin(origin)
    .setDestination(destination)
    .setMode(mode)
    .getDirections();

  if (!data) {
    throw new Error('No route found!');
  }

  const { legs: [{ distance: { text: distance } } = {}] = [] } = data;
  return distance;
};
Reply all
Reply to author
Forward
0 new messages