根据缩放级别分组/取消分组 MKAnnotation(并保持快速)
我有一个地图视图,其中有很多注释,其中大多数彼此非常接近。我想要做的类似于 iOS 上的照片应用程序,当注释彼此太接近时,它们会被分组;每当您缩小时,如果它们相距太远,它们就会取消分组。
我已经看到这个问题但给出了答案这并不是我真正想要的。
我正在寻找一个我可以自己实现的库或算法。
I have a mapview that has a lot of annotations, most of them are very close to each other. What I want to do is similar to the Photo app on iOS where annotations are grouped when they are too close to each other and whenever you zoom out, they un grouped if they are too far apart.
I have seen this question already but the answer given isn't really what I was looking for.
I'm looking for either a library or a algorithm that I could implement myself.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Apple 的 WWDC 2011 会议视频之一展示了如何做到这一点。转到 https://developer.apple.com/videos/wwdc/2011/ (必须是注册开发人员)并滚动到标题为“使用 MapKit 可视化地理信息”的视频。基本思想是使用屏幕外地图视图来保存所有注释,并根据需要将它们复制到屏幕地图视图,确保您不会尝试一次显示太多注释。当您缩放时,它甚至可以使用注释制作漂亮的动画。
One of Apple's WWDC 2011 session videos shows how to do exactly this. Go to https://developer.apple.com/videos/wwdc/2011/ (must be registered developer) and scroll to the video titled "Visualizing Information Geographically with MapKit". The basic idea is to use an offscreen map view to hold all of your annotations, and copy them to the onscreen map view as needed, making sure that you're not trying to show too many at once. It even does the nifty animation with the annotations as you zoom.
请查看此处以了解完整的答案。它包含 MapKit 和 Google 地图的实现。该代码的灵感来自 WWDC 2011 视频,在我的应用程序中运行良好。
无论如何,我在这里发布了 MapKit 的代码,但我的其他答案中有一些有用的注释。
Have a look here in order to see the full answer. It contains both implementations for MapKit and Google Maps. The code is inspired by WWDC 2011 video and works very well in my app.
I post the code for MapKit here anyway but there are a few useful remarks in my other answer.