Google Apps Script API
    Preparing search index...

    Allows for the retrieval of directions between locations. The example below shows how you can use this class to get the directions from Times Square to Central Park, stopping first at Lincoln Center, plot the locations and path on a map, and send the map in an email.

    // Get the directions.
    var directions = Maps.newDirectionFinder()
        .setOrigin('Times Square, New York, NY')
        .addWaypoint('Lincoln Center, New York, NY')
        .setDestination('Central Park, New York, NY')
        .setMode(Maps.DirectionFinder.Mode.DRIVING)
        .getDirections();
    var route = directions.routes[0];
    
    // Set up marker styles.
    var markerSize = Maps.StaticMap.MarkerSize.MID;
    var markerColor = Maps.StaticMap.Color.GREEN
    var markerLetterCode = 'A'.charCodeAt();
    
    // Add markers to the map.
    var map = Maps.newStaticMap();
    for (var i = 0; i < route.legs.length; i++) {
      var leg = route.legs[i];
      if (i == 0) {
        // Add a marker for the start location of the first leg only.
        map.setMarkerStyle(markerSize, markerColor, String.fromCharCode(markerLetterCode));
        map.addMarker(leg.start_location.lat, leg.start_location.lng);
        markerLetterCode++;
      }
      map.setMarkerStyle(markerSize, markerColor, String.fromCharCode(markerLetterCode));
      map.addMarker(leg.end_location.lat, leg.end_location.lng);
      markerLetterCode++;
    }
    
    // Add a path for the entire route.
    map.addPath(route.overview_polyline.points);
    
    // Send the map in an email.
    var toAddress = Session.getActiveUser().getEmail();
    MailApp.sendEmail(
      toAddress,
      'Directions',
      'Please open: ' + map.getMapUrl() + '&key=YOUR_API_KEY', {
        htmlBody: 'See below.<br/><img src="cid:mapImage">',
        inlineImages: {
          mapImage: Utilities.newBlob(map.getMapImage(), 'image/png')
        }
      }
    );
    

    See also

    Google Directions API

    interface DirectionFinder {
        addWaypoint(latitude: number, longitude: number): DirectionFinder;
        addWaypoint(address: string): DirectionFinder;
        clearWaypoints(): DirectionFinder;
        getDirections(): any;
        setAlternatives(useAlternatives: boolean): DirectionFinder;
        setArrive(time: GoogleAppsScript.Base.Date): DirectionFinder;
        setAvoid(avoid: string): DirectionFinder;
        setDepart(time: GoogleAppsScript.Base.Date): DirectionFinder;
        setDestination(latitude: number, longitude: number): DirectionFinder;
        setDestination(address: string): DirectionFinder;
        setLanguage(language: string): DirectionFinder;
        setMode(mode: Mode): DirectionFinder;
        setOptimizeWaypoints(optimizeOrder: boolean): DirectionFinder;
        setOrigin(latitude: number, longitude: number): DirectionFinder;
        setOrigin(address: string): DirectionFinder;
        setRegion(region: string): DirectionFinder;
    }
    Index

    Methods