问题描述
我可以使用坐标绘制路线。
我试图在按清除时删除道路,但不起作用。
在我按下清除地图按钮时执行的函数下面。
函数Clear(){alert(directionsDisplay.length); // MyArray = []; directionsDisplay.setMap(NULL); document.getElementById(Coords)。value =; document.getElementById(Coords)。disabled = false; document.getElementById(btnAdd)。disabled = false;}
这是。
任何建议吗?
谢谢!
当您点击清除地图按钮时: Uncaught TypeError:directionsDisplay.setMap不是函数
:
directionsDisplay.setMap(null);
因为directionsDisplay是一个数组( var directionsDisplay = [];
),并且没有 setMap
方法。这条线应该是最低限度的(假设你只想要这个工作一次):
directionsDisplay [0] .setMap(null );
I can draw route using coordinates.
I'm trying to delete the road when I press clear, but it does not work.
Below the function I execute when pressing the button "Clear map".
function Clear() {
alert(directionsDisplay.length);
// MyArray = [];
directionsDisplay.setMap(null);
document.getElementById("Coords").value = "";
document.getElementById("Coords").disabled = false;
document.getElementById("btnAdd").disabled = false;
}
Here is my code.
Any suggestion ?
Thanks !
I get a javascript error on your page when I click the "Clear Map" button: Uncaught TypeError: directionsDisplay.setMap is not a function
on this line:
directionsDisplay.setMap(null);
Because directionsDisplay is an array (var directionsDisplay = [];
), and doesn't have a setMap
method. That line should be at a minimum (assuming you only want this to work once):
directionsDisplay[0].setMap(null);
这篇关于使用按钮删除路线谷歌地图API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!