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();
});
所以我在这里创建变量来显示我选择的建筑物的位置上的自定义标记。但我也想调用这个函数,它计算并显示从用户当前位置到单击图标位置的方向。
有帮助吗?