0
我對javascript的知識不是很好,所以我不確定如何從同一個事件監聽器加載第二個函數。試圖用現有的eventListener調用一個函數
var tutsImg = "houseProxy.jpg";
var kingTuts = new google.maps.LatLng(55.86256, -4.265);
var tutsDisplay = new google.maps.Marker({
position: kingTuts,
map: map,
icon: tutsImg,
title:"King Tut's Wah Wah Hut"
});
var contentString = '<div id="content">'+
'<div id="siteNotice">'+
'</div>'+
'<h2 id="firstHeading" class="firstHeading">King Tuts Wah Wah Hut</h2>'+
'<div id="bodyContent">'+
'</div>'+
'</div>';
var infowindow = new google.maps.InfoWindow({
content: contentString
});
// Creating directions
function calcRoute() {
var request = {
origin: 'Glasgow',
destination: kingTuts,
travelMode: google.maps.DirectionsTravelMode.DRIVING
}
directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(response);
}
});
}
google.maps.event.addListener(tutsDisplay, 'click', function() {
infowindow.open(map,tutsDisplay);
calcRoute();
});
所以我在這裏創建變量來顯示我選擇的建築物的位置上的自定義標記。但我也想調用這個函數,它計算並顯示從用戶當前位置到單擊圖標位置的方向。
有幫助嗎?