使用按钮删除路线谷歌地图API [英] Remove route google maps API using button

查看:148
本文介绍了使用按钮删除路线谷歌地图API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以使用坐标绘制路线。



我试图在按清除时删除道路,但不起作用。



在我按下清除地图按钮时执行的函数下面。

函数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); 

updated fiddle

这篇关于使用按钮删除路线谷歌地图API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆