如何检查Google Maps视口中是否有任何标记? [英] How to check if there are any markers within a Google Maps viewport?
本文介绍了如何检查Google Maps视口中是否有任何标记?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
一个完美的解决方案不需要逐个检查所有的标记,如果它包含在视口中,则为一个。
解决方案
我想出的最佳解决方案是
- 在应用程序启动时创建一个参考标记的数组 - 按1坐标排序,即纬度
- 获取视口边界
GMap2.getBounds()
(as paullb recommended)
- 取视口边界的低纬度并在数组中查找(最快到使用二进制搜索实现)
- 检查每个以下标记是否适合视口内(直到标记的纬度<=视口的高纬度)。
What is the most effcient approach to check if there are any markers within a viewport?
A perfect solution wouldn't require checking all the markers one-by-one if it's contained by the viewport.
解决方案The best solution that I came up with is to
- on the application launch, create an array with reference to markers - sorted by 1 coordinate, i.e. latitude
- get viewport's bounds with
GMap2.getBounds()
(as paullb suggested) - take lower latitude of viewport boundaries and look for it in the array (fastest to achieve with binary search)
- check if every following marker fits within the viewport (up to marker's latitude <= viewport's upper latitude).
这篇关于如何检查Google Maps视口中是否有任何标记?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
- 获取视口边界
查看全文