使用沿路径/路径的距离来映射google-apps-script信息

时间:2012-08-07 01:38:05

标签: google-apps-script

我正在尝试找出一种使用地图脚本显示项目的方法,其中包含以下信息:

沿美国1号向北行驶10英里,在美国1号右侧(东侧)10英尺处绘制一个标记。例如,设置英里0从美国1号和主要街道的交叉点开始。

也许某人之前遇到过类似的事情或类似事情,并且会给我一些指示。

谢谢!

2 个答案:

答案 0 :(得分:2)

根据Eric的提示,我能够创建一个函数来从Google地图中获取道路中心线的折线。然后使用google api服务将该折线转换为纬度和经度坐标。从那时起,它就是所有球面几何编码。以下是我简陋的小代码:

//Function to grab a centerline from the Map Api
//start = lat and long for beginning of roadway centerline ie [27.64681, -82.38438]
//end = lat and long for end of roadway centerline ie [27.71248, -82.33518]
//startmile = beginning milepost
function grabmap(start, end, startmile){

  startmile = parseFloat(startmile);

  var points = [];
  var plinex = [];
  var pliney = [];


  var directions = Maps.newDirectionFinder().setOrigin(start).setDestination(end).getDirections();
// Much of this code is based on the template referenced in
// http://googleappsdeveloper.blogspot.com/2010/06/automatically-generate-maps-and.html
  for (var i in directions.routes) {
    for (var j in directions.routes[i].legs) {
      for (var k in directions.routes[i].legs[j].steps) {
// Parse out the current step in the directions
        var step = directions.routes[i].legs[j].steps[k];
// Call Maps.decodePolyline() to decode the polyline for
// this step into an array of latitudes and longitudes
        var path = Maps.decodePolyline(step.polyline.points);
        points = points.concat(path);
      }
    }
  }

  var lengthvector = (points.length / 2);
  for ( i = 0; i <= points.length; i++){
    if ( i % 2 == 0){
      plinex = plinex.concat(points[i]);
      pliney = pliney.concat(points[(i+1)]);
    }
  }
  var plineVector = new Array(plinex.length - 2);
    for ( i = 0; i <= plinex.length - 2; i++){
          plineVector[i] = new Array(2);
          plineVector[i][0] = plinex[i];
          plineVector[i][1] = pliney[i];
        }

return plineVector;
}

答案 1 :(得分:0)

我没有广泛使用地图服务,但它应该是可能的。您可以使用DiretionFinder获取沿路径的点的纬度和经度,然后进行一些数学计算以获得标记的偏移量。