Google マップの乗換案内に似たものをウェブサイトに表示したいので、同じ地図に複数の異なる種類の案内を表示しようとしています。たとえば、バスまで歩いて行き、バスに乗って別の通りに行き、最終目的地まで歩くという旅を見せたいと思います。
これを行うために、カスタム マーカーを使用して、同じマップ上で複数のルート リクエストの結果を取得しようとしています。私は change_map() と呼ばれる関数を持っています。これは、これらの旅行の 1 つの情報を地図上に表示することになっています。
私には2つの問題があります:
- マーカーはマップに表示されません。
- fitbounds のコメントを外すと、スタック制限を超えたというエラーが表示されます
私は JavaScript を初めて使用します。コードがうまくいかない場合は申し訳ありません。ご協力いただきありがとうございます。
var trip_map
function renderDirections(result) {
var directionsDisplay = new google.maps.DirectionsRenderer;
directionsDisplay.setMap(trip_map);
directionsDisplay.suppressMarkers = true;
directionsDisplay.setDirections(result);
}
function requestDirections(start, end) {
var directionsService = new google.maps.DirectionsService;
directionsService.route({
origin: start,
destination: end,
travelMode: google.maps.DirectionsTravelMode.DRIVING
}, function(result) {
renderDirections(result);
});
}
function change_map(pk) {
var myOptions = {
center: new google.maps.LatLng(-34.397, 150.644),
zoom: 8,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
trip_map = new google.maps.Map(document.getElementById("trip_map"),
myOptions);
var bounds = new google.maps.LatLngBounds();
for (var j = 0; j < latlngpairs.length; j++) {
var GPS = new google.maps.LatLng({lat:latlngpairs[0],
lng:latlngpairs[1]});
var end_marker = new google.maps.Marker({position: GPS,
map: trip_map,
title: "Hello World!"});
bounds.extend(end_GPS);
}
requestDirections(parts[j], parts[j+1]);
}
//trip_map.fitBounds(bounds);
}