更新 MapKit 注释副标题和图像 [英] Update MapKit annotation subtitle and image

查看:35
本文介绍了更新 MapKit 注释副标题和图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在网上搜索了一下,找到了一些关于如何做我想做的事情的想法,但我仍然想知道你认为我应该做什么.

I've searched a bit around the web and found a few ideas on how to do what I want, but I would still like to know what you think I should do.

这里是上下文:

我正在为 iOS 5 开发一个应用程序.我使用 MapKit 来显示地图,并向其中添加了大约 5000 个注释 - 是的,这看起来很多,但别担心,我使用了一个聚类库:).为了每次用户打开地图时都加载它们,我在我的 appDelegate 中创建它们(我创建了一个注释数组,并调用 [_mapView addAnnotations:[appDelegate.annotationsToAdd allObjects]]; 当我打开地图时).创建 annotationsToAdd 数组大约需要 10 秒,所以我认为这个解决方案工作得很好(你必须等待这 10 秒才能被授权打开地图,但你只等待一次,在应用程序启动时).在每个注释中,我都有一个指向对象的链接",该对象包含一个值数组(15 个浮点数).现在,当我创建注释时,subtitle 方法返回这些值之一.

I'm developing an app for iOS 5. I use MapKit to display a map, and I add around 5000 annotations to it - yup, that seems a lot, but don't worry, I use a clustering library :). In order not to load them every time the user opens the map, I create them in my appDelegate (I create an array of annotations, and call [_mapView addAnnotations:[appDelegate.annotationsToAdd allObjects]]; when I open the map). It takes about roughly 10 seconds to create the annotationsToAdd array, so I think this solution is working pretty well (you have to wait for those 10 seconds before being authorized to open the map, but you only wait once, at the launch of the app). In each of those annotations, I have a "link" to an object, which contains an array of values (15 floats). For now, when I create the annotation, the subtitle method returns one of those values.

在我的地图的 ViewController 中,我有 2 个分段控件.第一个有 3 个段,第二个有 5 个,它给出了 15 种组合 - 是的,这与我的注释中的对象数组具有的值数量相同:)

In my map's ViewController, I have 2 segmented controls. The first one has 3 segments, the second one has 5, which gives 15 combinations - yup again, that's the same number of values the array of the object in my annotation has :).

所以您可能已经看到我的问题出现了,我想更新地图上每个注释的副标题(即使是集群中的注释,因为集群根据它持有的别针).我还想要的是根据注释副标题的值更新 annotationView 的颜色/图像.

So you may have seen my problem coming, I would like to update the subtitle of every annotation on my map (even the ones in the clusters, as the cluster gives an average value based on the pins it holds). What I would also want is to update the annotationView's color/image based on the value of the annotation's subtitle.

我可能错了,但根据我的研究,我知道您必须删除所有注释,然后重新创建所有注释才能做到这一点.你明白这在我的情况下不是一个选项.我不能让用户每次更改其中一个控件的值时都等待 10 秒.

I may be wrong, but based on my research, I understand that you have to remove all the annotations, and recreate them all in order to do that. you understand that this is not an option in my case. I can't make the user wait 10 seconds every time he changes the value of one of the controls.

我看到一篇关于 KVO 的文章:这可能是一个可行的解决方案吗?

I saw an article on KVO: could that be a working solution ?

我不太了解 NSNotification,但我应该使用它们吗?

I don't know much about NSNotification, but should I use them ?

我非常感谢您的帮助,我更希望得到详细的答复,向我展示在我明显不常见的情况下应遵循的步骤.

I would really appreciate your help, and I would even more appreciate a detailed answer, showing me the steps to follow in my apparently uncommon situation.

提前致谢.

推荐答案

很抱歉我还没有完全理解你的情况,但我觉得我正朝着解决类似问题的方向努力,所以我会尝试与你分享我的想法.我会用你的话作为我回答的指导:

I am sorry if I haven't finally understood your situation quite well, but I feel like I am moving towards solving a similar problem so I'll try to share my thoughts with you. I will use your words as the guides for my response:

您必须等待 10 秒才能获得授权打开地图"

您是否了解以下 协议方法(参见 http://developer.apple.com/library/IOs/#documentation/MapKit/Reference/MKOverlayView_class/Reference/Reference.html):

Do you know about the following <MKOverlayView> protocol methods (see http://developer.apple.com/library/IOs/#documentation/MapKit/Reference/MKOverlayView_class/Reference/Reference.html):

- (void)drawMapRect:(MKMapRect)mapRect zoomScale:(MKZoomScale)zoomScale inContext:(CGContextRef)context
- (BOOL)canDrawMapRect:(MKMapRect)mapRect zoomScale:(MKZoomScale)zoomScale

(假设您在整个世界地图上有 5000 个图钉,而不是每 1 公里,即不是大量的图钉)您可以将五千个图钉分成几部分,因此图钉的每个部分都将由对应的 MKMapRect 区域正在被绘制在地图上.因此,您的地图根据需要填充了图钉/注释,仅适用于任何给定时间的特定区域.根据您的情况,这可能会带来巨大的加速.

(Assuming that you have 5000 pins on entire world map, not on every fx 1km, i.e. not SO LARGE amount of pins) You can split your five thousands into the portions, so each portion of pins is to be populated by the corresponding MKMapRect region which is being drawn on the map. So your map is populated with pins/annotations, by demand, only for particular region at any given time. Depending on your situation this could bring a huge speed up.

这是使用 MKMapRect 磁贴的非常好的演示:https://github.com/mtigas/iOS-MapLayerDemo - 仅填充特定地图片段的信息.您也可以google诸如地图图块 256px"之类的内容,以了解地图的绘制方式.

This is a very good demonstration of working with MKMapRect tiles: https://github.com/mtigas/iOS-MapLayerDemo - populate with information only particular pieces of map. Also you may google something like "Map tiles 256px" to understand how the maps are being drawn.

我知道您必须删除所有注释,然后重新创建所有注释才能执行此操作."

为什么要重新创建?您确实可以访问地图上已有的所有注释 - 为什么不遍历关联的注释类并更新它们的字幕?

Why recreate? You do have an access to all the annotations that are already there on your map - why not just iterate through your associated annotations classes and update theirs subtitles?

类似于:

我希望我的观点能够解决您的问题/情况的范围.

I hope that my points do address the scope of your question/situation.

这篇关于更新 MapKit 注释副标题和图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆