how to remove a single marker from google map

前端 未结 1 1183
逝去的感伤
逝去的感伤 2021-02-06 11:53

I am working on google maps i am trying to add markers to a google map and then tried to remove it but now as i have done both adding and removing with the code below

         


        
相关标签:
1条回答
  • 2021-02-06 12:35

    The easier answer is that you don't remove the marker from the markers array. All you do is identify the marker you want to remove from the map and then use setMap(null).

    markers[indexOfMarker].setMap(null);
    

    This way you can use the following if you want to add the marker back at some point:

    markers[indexOfMarker].setMap(map);
    
    0 讨论(0)
提交回复
热议问题