同一坐标中多个标记的解决方案,Google 地图混搭
我正在制作一个混搭,其中缩略图将显示在谷歌地图上。
问题是许多缩略图将共享相同的坐标。因此,如果我像标记一样绘制它们,它们将一个在另一个之上。
您是否见过针对这个问题的创造性解决方案?谢谢
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
我正在制作一个混搭,其中缩略图将显示在谷歌地图上。
问题是许多缩略图将共享相同的坐标。因此,如果我像标记一样绘制它们,它们将一个在另一个之上。
您是否见过针对这个问题的创造性解决方案?谢谢
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(5)
有一些 Javascript 库可以实现集群,并且很容易集成到现有的混搭中:
您还可以阅读这篇博文 概述了各种替代方案。
There are a few Javascript libraries that implement Clustering and are very easy to integrate into an existing mashup:
You can also read this blog post which goes over the various alternatives.
您需要查找术语“聚类”。您基本上只显示一个标记,表明该位置实际上有多个标记。然后,在适当的缩放级别,标记开始单独显示。
如果它们位于完全相同的坐标并且永远不会发散,那么您将需要实现当您将鼠标悬停在聚集标记上时在屏幕上弹出的内容(例如包含缩略图列表的浮动 DIV,供用户查看)选择/查看,甚至是上下文菜单,他们可以右键单击群集并选择单个项目)
You'll want to look up the term Clustering. You basically just show one marker that indicates there are actually more than one marker at that location. Then at an appropriate zoom level the markers start to appear separately.
If they are at the exact same coordinates and will never diverge, then you will need to implement something that pops-up on the screen when you hover over the clustered marker (like a floating DIV that contains a list of the thumbnails for the person to select/view, or even a context menu where they can right click the cluster and select an individual item)
使用聚类。将一组标记作为簇。一个簇将在内部呈现许多标记。
Use clustering .make group of markers as cluster.one cluster will present many markers inside.
我有一个优雅而美丽的解决方案:
片段的完整代码:
https://github.com/master255/MapFragment
I've got an elegant and beautiful solution:
Full code of Fragment:
https://github.com/master255/MapFragment
聚类当然很有用,但它并没有解决最初的问题——如果标记共享相同的精确坐标,则如何显示标记。 Google Maps API v3 根本不这样做。它只显示其中之一。
@RedBlueThing 建议的集群解决方案不能解决这个问题。
有几个选择。 @Bryan 建议 - 手动进行一些预处理,并将描述性信息放入最后一个标记的信息窗口中。
或者 - 我更喜欢 - 是对标记进行预处理,以稍微(10m 左右)改变共享相同确切位置的标记的坐标。如果您有能力放弃这种精度水平。请在此处查看此类解决方案 http:// techxplorer.com/2010/02/05/managing-markers-with-the-same-coordinates-in-a-google-map/。我进一步修改了代码 - 请参阅此处 https://gist.github.com/873142。
Clustering is certainly useful, but it doesn't address the original question - which is how to display markers if they share the same exact coordinates. Google Maps API v3 simply doesn't do that. It just displays one of them.
Clustering solutions suggested by @RedBlueThing do not address this.
There are a couple of options. One was suggested by @Bryan - to do some pre-processing manually, and put descriptive information in the info window for the last marker.
Alternatively - which I prefer - is to pre-process the markers to just ever so slightly (10m or so) alter the coordinates of those that share the same exact location. If you can afford to give up that kind of level of precision. See one such solution here http://techxplorer.com/2010/02/05/managing-markers-with-the-same-coordinates-in-a-google-map/. I have further modified the code - see here https://gist.github.com/873142.