basictomonokai

距離測定のGAS

Oct 23rd, 2018
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function myFunction() {
  2.   var frompoint = '横浜駅';
  3.   var topoint = '東京スカイツリー';
  4.   var kekkaDistance = distanceBetweenPoints(frompoint,topoint);
  5.   Logger.log(kekkaDistance);
  6. }
  7.  
  8.  
  9. function distanceBetweenPoints(start_point, end_point) {
  10.   // get the directions
  11.   var directions = Maps.newDirectionFinder()
  12.     .setOrigin(start_point)
  13.     .setDestination(end_point)
  14.     .setMode(Maps.DirectionFinder.Mode.DRIVING)
  15.     .getDirections();
  16.   // get the first route and return the distance
  17.   var route = directions.routes[0];
  18.   var distance = route.legs[0].distance.text;
  19.   return distance;
  20. }
Add Comment
Please, Sign In to add comment