2013-06-27 46 views
0

我有兩點經緯度網絡墨卡託:如何在javascript中找到兩個lat長對之間的X個點數?

var point1 = [32.043732,-99.563599] 

var point2 = [32.591515,-97.630005] 

如何我會在JavaScript函數,採用X點這兩個經緯度對之間獲得3分?

+2

兩個點定義的直線。所以使用標準線方程...或者你需要產生大圓弧曲線點嗎? –

回答

0

Linear interpolation

function getPoints(point1, point2, num) { 
    var d0 = (point2[0] - point1[0])/(num + 1); 
    var d1 = (point2[1] - point1[1])/(num + 1); 
    var points = []; 
    for (var i = 1; i <= num; i++) { 
     points.push({ 
      x: point1[0] + d0 * i, 
      y: point1[1] + d1 * i 
     }); 
    } 
    return points; 
} 

jsfiddle

相關問題