iOS SDK - 在任何显示的地图范围内显示 # 个最重要的 POI
我有一个数据结构,其中包含:
- 一个
NSNumber
,显示 POI(兴趣点)的重要性; - 一个
CLLocation
,包含 POI 的坐标。
假设我能够按重要性对 POI 进行排序,并且每个 POI 都有一个独特的重要性因素,那么获取包含位于 MKMapView
中显示区域内的 POI 的子数组的最佳方法是什么?
简单地检查每个 POI 似乎效率很低,因为我可能有几千个 POI,并且我想在每次缩放级别更改时重复此过程(因此在任何显示区域我只显示 # 个最重要的 POI)。
I have a data structure, containing amongst others :
- an
NSNumber
showing the importance of the POI (point of interest) - a
CLLocation
containing the coordinates of the POI.
Supposing I am able to order the POIs by importance and each POI has a unique importance factor, what is the best way to get a subarray with the POIs that are inside the displayed region in my MKMapView
?
Simply checking every POI seems inefficient, as I may have a couple of thousands of POIs, and I want to repeat this process every time zoom level changes (so at any displayed region I show only the # most important ones).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我猜你要找的是:
引用 Apple 文档 :
请注意,它仅在 iOS 4.2 及更高版本中可用,恐怕除了以前的 iOS 版本中的自定义代码之外没有其他解决方案。
编辑关于您的评论:我的猜测是,对于几千个注释,上述方法应该可以解决问题,
MKAnnotation
是一个轻量级协议,通过坐标过滤来扫描数组应该可以。但要注意不要添加数千个在 iPhone 4 上工作的 MKAnnotationView,已经做到了,但你几乎无法滚动地图:)那么我建议:
关于内存,嘿,这些设备很容易为您的应用程序提供至少 64MB 的可用内存,如果没有,将会杀死一些进程,不要被吓到几K的注释!只需注意内存泄漏,尤其是在此类密集进程上。
I guess what you're looking for is :
Quoting Apple documentation :
Take care that's it's only Available in iOS 4.2 and later, I'm afraid there is no other solution than custom code in previous iOS versions.
EDIT About your comment : My guess is that for a few thousands annotation, the above method should do the trick,
MKAnnotation
is a lightweight protocol, scanning an array by filtering on coordinate should be ok. But beware on not adding thousands ofMKAnnotationView
, that works on an iPhone 4, already did it, but you almost can't scroll map :)Then I would suggest :
About memory, hey, these devices have easily at least 64MB free memory for your app, and will kill some processes if not, don't be scared by a few K of annotations! Just take care of memory leaks, especially on such intensive processes.