How do I find all the markers that are currently visible on Google Maps V3?

I have a sidebar on which I want to display all the markers placed on a Google map. and when I change Veiwport by dragging a map. The list of markers should be updated.

+4
source share
1 answer

To get all the markers first, you need to find the borders of the current viewport, then you need to loop all the markers and see if they are in this binding. The following is an example.

var bounds =map.getBounds();

for(var i = 0; i < markers.length; i++){ // looping through my Markers Collection        
if(bounds.contains(markers[i].position))
 console.log("Marker"+ i +" - matched");
}
+3
source

All Articles