私はサイクリングのウェブサイトを作成しています。その目的は、その距離のルートを作成するために、開始と終了と距離を入力させることです。これは私がこれまで持っているものです:JavaScript - Google Maps API:経路の距離を調整する
http://kellyd52.000webhostapp.com/hexTestTest.html
(^^最良の例を見て、現在の位置と距離を使用して)私は2つを追加することにより、おおよその距離を見つけることができ、今のよう
ルートを半六角形のように見えるようにする(これは通常5/10km以内の距離を望む)。さて、これらのウェイポイントを少し調整して、ルートの距離がより正確になるようにする必要があります。私はそれが完璧に動作し、他の機能、それを使用していても、fillWaypts
では動作しません
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
}
部分:これは私がそれを行うために使用している機能です。そのためのコードは次のとおりです。
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
に正しく送信され取得されないことが理由としていかなる理由がありますか?