如何查找Google Maps V3上当前可见的所有标记?

Vis*_*rma 5 google-maps google-maps-markers

我有一个侧边栏,我想在其上显示放置在Google地图上的所有标记.当我通过拖动地图来改变Veiwport.标记列表应该刷新.

Shi*_*ven 6

要首先获取所有标记,您必须找到当前视口的边界,然后您必须循环所有标记并查看它们是否包含在边界中。下面是一个例子。

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");
}
Run Code Online (Sandbox Code Playgroud)

  • 我认为问题是如何从地图本身获取地图上当前可见的所有标记。我不知道这是否可能。 (2认同)