最近、アプリケーションの出発地と目的地の間に「ウェイポイント」があるDirectionsServiceを使用すると、視覚的に意味のないこれらの「ジグザグ」ルートが返されるようになりました。
見た目はすべて順調ですが、7番目のウェイポイントの後のどこかで、ルートは劇的なジグザグに前のウェイポイントに戻り、適切なパスに戻ろうとしているように見えます。
私が言おうとしていることを示す画像を添付し、物事がうまくいかない点を赤で指摘しました。さらに、以下のサンプルコードを含め、問題の実用的なデモンストレーションをここに投稿しました。
http://dev.anytraq.com:8080/test.html(作業バージョン)
ここの誰かがそのような問題に遭遇したのか、それとも何が起こっているのかを明らかにすることができるのだろうかと私は思っていました。以下に示すように、コードは非常に単純です。基本的に、起点と終点のLatLngオブジェクト、およびその間の8つのウェイポイントを定義し、DirectionsServiceに送信します。
私は頭に浮かぶかもしれないありとあらゆる提案に感謝します、私は完全に困惑しています。
<!DOCTYPE html>
<html>
<head>
<title>ZigZagged Directions Example</title>
<meta charset="UTF-8">
<style type="text/css">
html, body, #map_canvas {
margin: 0;
padding: 0;
height: 100%;
}
</style>
<script type="text/javascript"
src="https://maps.googleapis.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
var map;
function initialize() {
// map options
var myOptions = {
zoom: 8,
center: new google.maps.LatLng(-34.397, 150.644),
mapTypeId: google.maps.MapTypeId.ROADMAP
};
// the map
map = new google.maps.Map(document.getElementById('map_canvas'), myOptions);
// directions service
directionsService = new google.maps.DirectionsService();
// Define our origin position, the start of our trip.
originPosition = new google.maps.LatLng('37.66258', '-121.87058');
// Define 8 waypoints to place between the origin and the destination
waypoint1 = new google.maps.LatLng('37.65638', '-121.87750');
waypoint2 = new google.maps.LatLng('37.64333', '-121.88174');
waypoint3 = new google.maps.LatLng('37.63676', '-121.88447');
waypoint4 = new google.maps.LatLng('37.60746', '-121.87343');
waypoint5 = new google.maps.LatLng('37.57868', '-121.87702');
waypoint6 = new google.maps.LatLng('37.56368', '-121.90382');
waypoint7 = new google.maps.LatLng('37.54175', '-121.92334');
waypoint8 = new google.maps.LatLng('37.51806', '-121.94201');
// push the waypoints defined above into an array
wayPointArray = new Array();
wayPointArray.push({location: waypoint1, stopover: false});
wayPointArray.push({location: waypoint2, stopover: false});
wayPointArray.push({location: waypoint3, stopover: false});
wayPointArray.push({location: waypoint4, stopover: false});
wayPointArray.push({location: waypoint5, stopover: false});
wayPointArray.push({location: waypoint6, stopover: false});
wayPointArray.push({location: waypoint7, stopover: false});
wayPointArray.push({location: waypoint8 , stopover: false});
// define our definition position, the last stop of our trip
destinationPosition = new google.maps.LatLng('37.50162', '-121.93034');
var request = {
origin: originPosition,
destination: destinationPosition,
waypoints: wayPointArray,
travelMode: google.maps.DirectionsTravelMode.DRIVING,
unitSystem: google.maps.DirectionsUnitSystem.METRIC,
optimizeWaypoints: false
};
directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
var polyOpts = {
strokeOpacity: 1.0,
strokeColor: '#0000FF',
strokeWeight: 2
}
var directionsDisplayOptions = {
suppressMarkers: false,
suppressInfoWindows: false,
preserveViewport: false,
polylineOptions: polyOpts
};
directionsRenderer = new google.maps.DirectionsRenderer(directionsDisplayOptions);
directionsRenderer.setMap(map);
directionsRenderer.setDirections(response);
} else {
console.info('could not get route');
console.info(response);
}
});
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>
<body>
<div id="map_canvas"></div>
</body>
</html>