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是未定义的.