昨日の質問の続きです。
ZERO_RESULTS を返すウェイポイント付きの Google ルート案内サービス
モール博士は、directions_changed
リスナーが再び発砲すると言いました。彼らは正しかった。無限に発射しています。このリスナーを配置するより良い場所があるかどうか、または設定された期間内に起動できる回数を制限する方法があるかどうか疑問に思っています。
function route(waypoint) {
distance = 5; // Default distance
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
};
}
var directionRendererOptions = { draggable: true };
// Make the directions request
directionService.route(request, function(result, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setOptions(directionRendererOptions);
directionsDisplay.setDirections(result);
directionsDisplay.setMap(map);
var path = result.routes[0].overview_path;
// more code here that won't matter
}
else {
alert("Directions query failed: " + status);
}
//listener for dragged route/polyline
google.maps.event.addListener(directionsDisplay, 'directions_changed', function(){
var waypoints = directionsDisplay.getDirections().routes[0].legs[0].via_waypoints||[];
for(var i=0;i<waypoints.length;++i){
waypoints[i]={stopover:true,location: waypoints[i]}
}
route(waypoints);
});
});
}
編集:自分自身をよりよく説明する必要があります。基本的に、ルートを再描画しようとすると、 の無限ループが発生しdirections_changed
ます。
また、この質問を見ている人にとっては、反対票を投じる必要はないと思います。私は調査や努力を怠りませんでした。ドキュメントのウェイポイントの部分はひどいものであり、LatLng オブジェクトを介してウェイポイントを使用しようとした例はありません。彼らは場所だけを使用しました。