Remove one of many markers on Google maps with javascript

梦想与她 提交于 2019-12-01 08:10:19

Outside of your for loop define an Array that will hold all added markers. E.g. allMarkers = []

Inside of your for loop after creating the marker, push it in said Array. E.g. allMarkers.push(marker)

When you want to remove the first marker: allMarkers[0].setMap(null), or the third marker: allMarkers[2].setMap(null)

Yes, this is possible. The Google Maps documentation covers this fully, including code examples, etc. Essentially markers are overlays rather than the map itself. You can put these overlays into an array and then use setMap() to null to hide.

Fully documentation here.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!