zaterdag 30 januari 2021

Travel advice #GoogleAppsScript

 


I would like to send clients a travel advice (url) but I don't know how to do that with the Maps Service.

Luckely the website of the 'Nederlandse Spoorwegen' offers a possibility to do what I want to do (with some Google Apps Script). 

function travelAdvice(arriveTime,labelOrigin,labelDestination){

var geoOrigin = geoCodeAddress(labelOrigin);
var geoDestination = geoCodeAddress(labelDestination);

var urlTravelAdvice = "https://www.ns.nl/reisplanner/#/?"
urlTravelAdvice += "vertrek=" + geoOrigin;
urlTravelAdvice += "&vertrektype=geo&vertreklabel=" + labelOrigin;
urlTravelAdvice += "&aankomst=" + geoDestination;
urlTravelAdvice += "&aankomsttype=geo&aankomstlabel="+ labelDestination;
urlTravelAdvice += "&type=aankomst&tijd=" + arriveTime; //yyyy-MM-ddThh:mm

return travelAdvice;
}

function geoCodeAddress(address){
/*
https://developers.google.com/apps-script/reference/maps/geocoder#geocode(String)
*/
  if(address !== ""){
  var response = Maps.newGeocoder().geocode(address);
    for (var i = 0; i < response.results.length; i++) {
      var result = response.results[i];
    }
  }
return result.geometry.location.lat + "," +result.geometry.location.lng;
}

Updated: 31-01-2021

2 opmerkingen:

  1. Dear Mariette

    Thanks for you post but sometimes I can not understand what you are trying to do :)Could you show the result and the thinh which we have to do to see same result

    BeantwoordenVerwijderen
  2. For me Google Apps Script is still a kind of 'trial and error' ;-).

    In this blog I tried to get a link (from the Dutch Railway Operator "Nederlandse Spoorwegen" with some help of #GAS) behind which is a public transport advice how to travel by public transport from A to B and arrive at a certain time.

    Thanks for your response.

    BeantwoordenVerwijderen