function calcRoute() {
var start = document.getElementById("start_").value;
var end = document.getElementById("end_").value;
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);
}
});
}
在Chrome中提供错误消息:"未捕获的TypeError:无法调用方法' setDirections'未定义"。有人可以建议修复这个吗?感谢名单
答案 0 :(得分:6)
您缺少(全局变量)
//var directionsService = new google.maps.DirectionsService();
var directionsDisplay = new google.maps.DirectionsRenderer({ 'map': map });
所以directionsDisplay
未定义。