GoogleMapsDirectionsServiceに奇妙な問題があります。入力データが同じ場合は、異なるルートが返されます。これが私のコードのサンプルです
var path = [];
path.push(new google.maps.LatLng(51.10600101811778, 17.025117874145508));
path.push(new google.maps.LatLng(51.1047951799623,17.02278971672058));
path.push(new google.maps.LatLng(51.10456276619924, 17.02208161354065));
path.push(new google.maps.LatLng(51.10131895649719, 17.029248476028442));
path.push(new google.maps.LatLng(51.100331957810134, 17.033969163894653));
path.push(new google.maps.LatLng(51.10001867395775, 17.032413482666016));
for (var i = 0; i <path.length-1; i++) {
var request = {
origin: path[i],
destination: path[i+1],
travelMode: google.maps.DirectionsTravelMode.WALKING
}
directionsService.route(request, function(results, status) {
if (status == google.maps.DirectionsStatus.OK) {
selected_path = selected_path.concat(results.routes[0].overview_path);
poly.setPath(selected_path);
poly.setMap(map);
}
})
}
呼び出し後の最初の関数は、開始点と終了点を常に接続する奇妙なポリラインを描画します。
2回目に呼び出されると、関数は正常に機能し、ルートが適切に描画されます。
これは、入力静的データの単なる例です。通常、私はマトリックスと動的マーカーの動的データを処理しますが、常に同じことが起こります。まず、始点が終点に接続されている+他の点間の奇妙な接続。2番目の呼び出し関数はうまく機能します。あなたの誰かがこの問題を解決する方法の手がかりを持っていますか?