使用 MarkerClusterer 在 Google 地图上折叠标记

发布于 2024-10-01 01:39:51 字数 341 浏览 0 评论 0原文

我正在将 GMaps V3 与来自 http://code.google 的 MarkerClusterer 结合使用。 com/p/gmaps-utility-library-dev/

地图上显示的标记是用户定义的并且经常折叠,因此无论您放大多少,聚类器始终显示一个位置有多个项目。但用户应该能够单击每个标记来查看信息窗口。

我尝试在服务器上随机化位置,但随机性不够随机,标记不断崩溃,只是不那么频繁。

你知道有什么方法可以解决这个问题吗?

I'm using GMaps V3 with MarkerClusterer from http://code.google.com/p/gmaps-utility-library-dev/

Markers displayed on the map are user-defined and often collapse, so no matter how much you zoom-in, the clusterer always shows there are multiple items in one location. But the user should be able to click each single marker to see the info window.

I tried randomizing location a bit on the server, but the random is not random enough and markers keep collapsing, just not so often.

Do you know any way to deal with this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

凯凯我们等你回来 2024-10-08 01:39:51

我遇到了这个问题,并通过定义“maxZoom”的构造函数属性来解决它,该属性低于 Google 地图的 maxZoom:

var markerCluster = new MarkerClusterer(map, markers, { maxZoom: 18 });

I had this problem and solved it by defining a constructor property of "maxZoom" that was lower than the maxZoom for the Google map:

var markerCluster = new MarkerClusterer(map, markers, { maxZoom: 18 });
生寂 2024-10-08 01:39:51

回复OP在我之前的回答中的评论,因为它不适合评论框:

这可以防止聚类器对标记进行分组,但是当坐标相同时,所有标记都会保持在彼此之上。您知道有什么解决方法吗?

我认为这是 Google 地图的预期行为 - 如果标记具有完全相同的纬度/经度,那么您会得到彼此重叠的标记。

一种可能的解决方法是仅将第一个标记添加到地图,然后当您尝试将另一个标记添加到已定义的纬度/经度(使用 JS 地图跟踪它们)时,您可以添加一个计数(或建立一个标记信息数组)并使用该信息更新信息窗口文本。例如,单击标记将显示一个信息窗口,显示此位置有 15 个“事物”,然后在其下方的列表中列出它们的名称和属性...

另一种可能性是通过添加随机数来“抖动”后续标记小数点末尾的纬度/经度。这样,当用户完全放大时,标记将稍微偏移。不过这个选项感觉有点“肮脏”。

Reply to OP's comment in my previous answer as it didn't fit in the comment box:

This prevents clusterer from grouping the markers, but when the coordinates are identical all markers stay on top of each other. Do you know any workaround for this?

I think that is the expected behaviour with Google maps - if markers have the exactly the same lat/lng then you get the markers on top of each other.

One possible workaround is to only add the first marker to the map and then when you attempt to add another marker to a lat/lng already defined (keep track of them with a JS map), you could add a count (or build up an array of marker info) and update the infowindow text with that information. E.g. clicking on the marker would then show an infowindow saying there are 15 "things" at this location and then list their names and attributes in a list under it...

Another possibility is to "dither" subsequent markers by adding a random number to the end of the decimal lat/lng. That way when the user zooms in all the way the markers will be slightly offset. This option feels a bit "dirty" though.

追风人 2024-10-08 01:39:51

添加标记时,您可以检查同一位置是否有其他标记,并且在信息窗口中您可以注意到有多个标记。

When adding a marker you can check if there are other markers at that same location and in the infowindow you could note that there are multiple markers.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文