简体   繁体   English

在 Google 地图上显示/隐藏标记

[英]Show/Hide Markers on Google Maps

I've seen the same question asked before but they all seemed specific to their situation and I didn't really understand as I am new to JS.我之前看过同样的问题,但他们似乎都针对他们的情况,我并不真正理解,因为我是 JS 新手。

I have a google map api already rendered.我已经呈现了一个谷歌地图 api。 I have created 3 separate arrays, each with a long list of locations for google map markers.我创建了 3 个单独的数组,每个数组都有一长串 google 地图标记的位置列表。 All the markers are currently showing on the map.所有标记当前都显示在地图上。

I have created 3 separate buttons and I would like each button to show/hide the markers in it's corresponding array.我创建了 3 个单独的按钮,我希望每个按钮都显示/隐藏其对应数组中的标记。

I really appreciate any help given, I have been searching for a week on how to do it and am sure its fairly simple but being new I'm just not understanding.我真的很感谢提供的任何帮助,我一直在寻找一个星期的时间来了解如何做到这一点,我确信它相当简单,但我是新手,我只是不明白。

when you create marker an object is returned, store this array of markers on a global var.创建标记时,返回一个对象,将此标记数组存储在全局变量上。 In the event of the button0 markers[0].setMap(map);在 button0 标记[0].setMap(map); In the event of the button1 markers[1].setMap(map);在 button1 标记的事件中[1].setMap(map);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM