Created
September 12, 2022 00:02
-
-
Save grant/c4433b1c1b8964617acd8a663a39dc53 to your computer and use it in GitHub Desktop.
Simple Maps Apps Script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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