-1
我正在創建一個騎車網站,目的是讓用戶輸入開始和結束以及距離,以創建距離的路線。這是我到目前爲止有:JavaScript - Google Maps API:調整路線距離
http://kellyd52.000webhostapp.com/hexTestTest.html
(^^使用當前的位置和距離看最好的例子)
截至目前,我可以通過增加兩個找一個大概距離航點,並使路線看起來像一個半六角形(這通常會提供距離所需的5/10公里內)。現在,我需要稍微調整這些路標,以便路線的距離更加精確。這是我使用的是做到這一點的功能:
function adjustHex(diff, total)
{
var diffMetres = diff * 500; //distance to compute and offset point
var nearest = total;
var eightPoints = [-135,-90,-45,0,45,90,135,180]; //compass bearings
var workOffOne = wayptsLatLngs[0]; //first waypoint of the hexagon
var workOffTwo = wayptsLatLngs[1]; // second waypoint of the hexagon
var tempPoint1;
var tempPoint2;
var bool; //boolean
for (var i = 0; i <eightPoints.length; i++)
{
for (var j = 0; j <eightPoints.length; j++) //double nested loop to find 8 different points around each waypoint
{
tempPoint1 = new google.maps.geometry.spherical.computeOffset(workOffOne, diffMetres, eightPoints[i]);
tempPoint2 = new google.maps.geometry.spherical.computeOffset(workOffTwo, diffMetres, eightPoints[j]);
checkThisHex(tempPoint1, tempPoint2,2,function(current) {
//checkThisHex checks the distance using the temp waypoints, returns the distance
bool = compareHex(current, nearest); // returns true if that distance is nearer to the user's distance, than the previous distance
if (bool == true)
{
document.getElementById("printInfo3").innerHTML = current;
//^prints the new distance -> This works, it always prints a distance that is nearer
nearest = current;
fillWaypts(tempPoint1, tempPoint2);
//fills the waypts array, which can be accessed by any function -> Used for the directionsService.route
}
});
}
}
return
}
不起作用爲fillWaypts
,即使我用它的另一個功能,它完美的作品的一部分。以上操作的代碼如下:
function fillWaypts(first, second)
{
wayptsLatLngs = [];
waypts = [];
wayptsLatLngs[0] = first;
wayptsLatLngs[1] = second;
waypts.push({
location: first,
stopover: false
});
waypts.push({
location: second,
stopover: false
});
return
}
是否有任何理由,爲什麼tempPoint1
和tempPoint2
可能不會得到正確發送到fillWaypts
?