0

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

沿着 US 1 向北 10 英里,在 US 1 的右侧(东)10 英尺处绘制一个标记。例如,设置 0 英里开始于 US 1 和 Main Street 之间的交叉点。

也许有人以前遇到过这种情况或类似的事情,并且会很友好地给我一些指示。

谢谢!

4

2 回答 2

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;
}
于 2012-09-20T14:08:36.873 回答
0

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

于 2012-08-10T18:31:31.417 回答