如何找到当前在Google Maps V3上可见的所有标记? [英] How to find all the the markers which are currently visible on Google Maps V3?

查看:89
本文介绍了如何找到当前在Google Maps V3上可见的所有标记?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个侧边栏,我希望显示放在Google地图上的所有标记。当我通过拖动地图来改变Veiwport时。标记列表应刷新。

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.

推荐答案

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

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");
}

这篇关于如何找到当前在Google Maps V3上可见的所有标记?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆