嗨,我在兩個標記之間的代碼中繪製路線。我需要做的是向這兩個標記添加一個點擊事件併爲每個標記設置一個信息窗口。我在很多網站上搜索無法找到解決方案。儘管它繪製標記之間的路線不能爲每個標記設置信息窗口。這裏是我的代碼...設置位於路線上的Google地圖標記的信息窗口(開始點和結束點)
function mapLocation() {
var directionsDisplay;
var directionsService = new google.maps.DirectionsService();
var map;
function initialize() {
directionsDisplay = new google.maps.DirectionsRenderer();
var chicago = new google.maps.LatLng(37.334818, -121.884886);
var mapOptions = {
zoom: 7,
center: chicago
};
map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
directionsDisplay.setMap(map);
google.maps.event.addDomListener(document.getElementById('routebtn'), 'click', calcRoute);
}
function calcRoute() {
var start = new google.maps.LatLng(37.334818, -121.884886);
//var end = new google.maps.LatLng(38.334818, -181.884886);
var end = new google.maps.LatLng(37.441883, -122.143019);
var request = {
origin: start,
destination: end,
travelMode: google.maps.TravelMode.DRIVING
};
directionsService.route(request, function (response, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(response);
directionsDisplay.setMap(map);
} else {
alert("Directions Request from " + start.toUrlValue(6) + " to " + end.toUrlValue(6) + " failed: " + status);
}
});
}
google.maps.event.addDomListener(window, 'load', initialize);
}
mapLocation();
如果有人有幫助,請給我一個解決方案來克服這種情況下 – SINFER 2015-03-31 05:19:13
請幫助這裏需要:) – SINFER 2015-03-31 05:51:48
削減我的代表請告訴我原因 – SINFER 2015-03-31 06:13:15