Skip to content

Instantly share code, notes, and snippets.

@grant
Created September 12, 2022 00:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save grant/c4433b1c1b8964617acd8a663a39dc53 to your computer and use it in GitHub Desktop.
Save grant/c4433b1c1b8964617acd8a663a39dc53 to your computer and use it in GitHub Desktop.
Simple Maps Apps Script
/**
* Gets driving directions from Mountain View to San Francisco.
* Derived from https://github.com/googleworkspace/apps-script-samples/blob/main/sheets/maps/maps.gs
* @customfunction
*/
function getDrivingDirections() {
// Set starting and ending addresses
var start = '1600 Amphitheatre Pkwy, Mountain View, CA 94043';
var end = '345 Spear St, San Francisco, CA 94105';
var directions = Maps.newDirectionFinder().setOrigin(start).setDestination(end).getDirections();
// html to text: https://stackoverflow.com/a/5002161
return directions.routes[0].legs[0].steps.map((s) => s.html_instructions.replace(/<\/?[^>]+(>|$)/g, ""));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment