現在、ページの To フィールドと From フィールドを適切にルーティングする DirectionsRenderer 関数があります。ルーティングが完了したら、overview_path を取得し、パスに基づいて Fusion Table から要素を読み込みます。これが完了したら、ウェイポイントを示す「directions_changed」を探すリスナーを設定しました。
google.maps.event.addListener(directionsDisplay, 'directions_changed', function(){
var wypnt = directionsDisplay.getDirections().routes[0].legs[0].via_waypoints.toString().match(/[^()]+/);
wypnt.toString().split(",");
wypnt = new google.maps.LatLng(wypnt[1],wypnt[0]);
var waypoint = [];
waypoint.push({ location: wypnt, stopover: true });
route(waypoint);
});
これを route() 関数 (To フィールドと From フィールドで正常に機能する関数) に戻すと、次のコード セクションが作成されます。
if(waypoint){
var request = {
origin: document.getElementById("search-input-from").value,
destination: document.getElementById("search-input-to").value,
waypoints: waypoint,
optimizeWaypoints: true,
travelMode: google.maps.DirectionsTravelMode.DRIVING
};
}
else{
var request = {
origin: document.getElementById("search-input-from").value,
destination: document.getElementById("search-input-to").value,
travelMode: google.maps.DirectionsTravelMode.DRIVING
};
}
コードの残りの部分は、次の if ステートメントに基づいています。
directionService.route(request, function(result, status) {
if (status == google.maps.DirectionsStatus.OK) {
//do stuff
}
else {
alert("Directions query failed: " + status);
}
};
残念ながら、「Directions query failed: ZERO_RESULTS」だけが返されます。なぜこれが起こっているのですか?ウェイポイントを形成する方法が間違っているのか、それとも何か他のものなのかわかりません。