Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 392
Vishnu Sharma Avatar asked Nov 22 '13 13:11

Vishnu Sharma


People also ask

How do you get all visible markers on current zoom level?

Use GMap2. getBounds() to find the bounding box. The use GLatLngBounds. containsLatLng() to check each marker to see if it is visible.

How do I find the marker ID on Google Maps?

getId() function to retrieve marker id.


1 Answers

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");
}
like image 72
Shishir Raven Avatar answered Nov 15 '22 11:11

Shishir Raven