how to get all markers on google-maps-v3

前端 未结 6 2075
南方客
南方客 2020-12-05 01:51

Is there a way to get all the markers on Google Maps?

6条回答
  •  眼角桃花
    2020-12-05 01:56

    If you mean "how can I get a reference to all markers on a given map" - then I think the answer is "Sorry, you have to do it yourself". I don't think there is any handy "maps.getMarkers()" type function: you have to keep your own references as the points are created:

    var allMarkers = [];
    ....
    // Create some markers
    for(var i = 0; i < 10; i++) {
        var marker = new google.maps.Marker({...});
        allMarkers.push(marker);
    }
    ...
    

    Then you can loop over the allMarkers array to and do whatever you need to do.

提交回复
热议问题