![](/img/trans.png)
[英]how to solve the error “ Uncaught TypeError: Cannot call method 'changePage' of undefined”
[英]How to solve “cannot call method … of undefined” error?
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'”。 有人可以建议解决此问题吗? 谢谢
您不见了(全局变量)
//var directionsService = new google.maps.DirectionsService();
var directionsDisplay = new google.maps.DirectionsRenderer({ 'map': map });
因此, directionsDisplay
是未定义的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.