更新MapKit注释字幕和图像 [英] Update MapKit annotation subtitle and image

查看:161
本文介绍了更新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(创建注解的数组,并调用 [_图形页面addAnnotations:[的appDelegate。 annotationsToAdd allObjects]; 当我打开地图)。大约需要大约10秒创建 annotationsToAdd 阵列,所以我觉得这个解决方案正在pretty好(你有被授权之前等待那些10秒打开地图,但你只能等待一次,在推出的应用程序)。在每一个这些注释的,我有一个链接到一个对象,其中包含的值(15浮子)的数组。现在,当我创建注释,在字幕方法返回的值之一。

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.

我看到志愿的文章:会是一个有效的解决方案。

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 ?

我真的AP preciate你们的帮助,我会更加AP preciate了详细的解答,显示我的步骤,我显然是罕见的情况来跟进。

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秒。

你知道以下&LT; MKOverlayView&GT; 协议方法(见<一href=\"http://developer.apple.com/library/IOs/#documentation/MapKit/Reference/MKOverlayView_class/Reference/Reference.html\" rel=\"nofollow\">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针脚,而不是在每一个FX1公里,即不销的那么大金额)您可以将五千分成的部分,因此,销的各个部分是由填充正被在地图上绘制相应的 MKMa preCT 区域。所以你的地图在任何给定的时间填充柱/注释,受需求,只有在特定的区域。根据您的情况,这可能带来巨大的提升速度。

(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.

这是 MKMa preCT 瓷砖工作的很好的示范:的 https://github.com/mtigas/iOS-MapLayerDemo - 用信息仅供地图的特定部分填充。你也可以谷歌类似地图图块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?

是这样的:

  • iPad Mapkit - Change title of "Current Location"
  • Annotation callout title does not change

我希望我的观点做解决您的问题/情形的范围。

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

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

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