Vishnu Sharma
Vishnu Sharma

Reputation: 53

How to find all the markers which are currently visible on Google Maps V3?

I have a sidebar on which I want to display all the markers which are placed on the Google Map. and when I change the Veiwport by dragging the map. The marker list should refresh.

Upvotes: 5

Views: 6036

Answers (1)

Shishir Raven
Shishir Raven

Reputation: 188

To Get all the Markers first you have to find the Bounds of the current Viewport then you have to loop all the markers and see if they are contains in the bound. The following is a 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");
}

Upvotes: 7

Related Questions