在 Google Maps API v3 中打开/关闭标记
我在获取 setMap(null); 时遇到问题每个人似乎都推荐使用的功能。
我相信这可能是我实现标记的方式有问题。
如果有人可以看一下并让我知道如果您发现有问题,我将不胜感激。
链接:http://www.dougglover.com/samples/UOITMap/v2/
请注意:上面的旧链接不会去任何地方。
I'm having trouble getting the setMap(null); function that everyone seems to be recommending to work.
I believe it may be a problem with the way I've implemented the markers.
If someone could take a look and let me know if you see something wrong I'd greatly appreciate it.
LINK: http://www.dougglover.com/samples/UOITMap/v2/
Please Note: Old link above, doesn't go anywhere.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不要使用 setMap(null) 来切换地图上的标记!因此,API 提供了 setVisible 方法,什么是适合该任务的方法。
Do not use setMap(null) for toggling markers on a map! Therefore the API offers the setVisible method, what is the appropriate method for that task.
基本问题是,如果您希望它起作用,您必须决定
markersTest
对象应该保存什么。您似乎无法决定markersTest
中的元素应该是标记还是应该是告诉您标记将放置在何处的数组。引用您的 javascript 文件,以下是您选中/清除复选框时执行的两个函数:
为了使
addTestMarkers
工作,markersTest
对象需要保存位置的描述标记应该消失。为了让clearOverlays
工作,markersTest
对象需要保存标记。我的建议是:将 javascript 文件顶部设置的
markersTest
对象更改为markerDestinations
,并在 javascript 文件顶部添加markersTest
初始化为:然后,将
addTestMarkers
修改为:关键的更改是使
addTestMarkers
实际上将标记放入markersTest
对象中。The basic problem is that if you want this to work you've got to make up your mind about what the
markersTest
object is supposed to hold. You can't seem to decide whether the elements inmarkersTest
should be markers or should be arrays that tell you about where markers are going to be placed.Quoting from your javascript file, here are the two functions that get executed when you check/clear the checkbox:
For
addTestMarkers
to work, themarkersTest
object needs to hold descriptions of where the markers should go. ForclearOverlays
to work, themarkersTest
object needs to hold markers.Here's my suggestion: change the
markersTest
object as you set it up at the top of the javascript file tomarkerDestinations
, and at the top of the javascript file havemarkersTest
initialized with:Then, modify
addTestMarkers
to:The key change is to make
addTestMarkers
actually put the markers into themarkersTest
object.