iPhone-在mapkit中更新注释字幕 [英] iPhone - Updating Annotation subtitle in mapkit
问题描述
我有一个带有标题和副标题的自定义地标.字幕实际上是使用反向地址解析器显示掉线引脚的地址.
I have a custom placemark with title and subtitle. The subtitle is actually displaying the address of the dropped pin using the reverse geocoder.
我有一个按钮,该按钮具有可将图钉放下的动作.此操作将获取用户的位置坐标,然后调用[geocoder start],后者会使用反向Geocoder获取完整地址,并生成自定义注释,然后调用[mapView addAnnotation:customPlacemark].
I have a button which has an action to drop the pin. This action gets the location coordinates of the user, and then calls [geocoder start] which gets the full address with Reverse Geocoder and generates the custom annotation and then calls [mapView addAnnotation:customPlacemark].
我的问题是,使用此顺序,当没有WiFi连接(只有3G或Edge)时,该引脚会掉落很多,因为它会想获取反向地理编码信息.
My problem is that using this sequence order, when there's no a WiFi connection (only 3G or maybe Edge) the pin takes a lot to drop because it's watigin to get the reverse geocoding info.
所以基本上,我需要不带字幕的情况下放下大头针,然后从viewDidAnnotation调用地理编码器,并在reverseGeocoder内部更新字幕,但是我不确定如何做到这一点.
So basically I need to drop the pin without a subtitle and from the viewDidAnnotation call the geocoder and inside the reverseGeocoder update the subtitle but I'm not sure how to do that.
我想显示不带地址详细信息的注释,并在从反向地址解析器获取信息时对其进行更新.
I want to display the annotation without the address details and update it when it gets the information from the reverse geocoder.
有什么建议吗?
预先感谢
推荐答案
MKMapView
通过KVO观察其注释的更改.因此,如果您以符合KVO的方式更新注释的属性,则它应该可以正常工作.
MKMapView
observes changes its annotations via KVO. Therefore if you update your annotation's properties in a KVO compliant manner, it should Just Work.
例如,当反向地址解析器返回注释的地址时,您首先宣布title
和subtitle
属性即将更改:
For example, when the reverse geocoder returns an address for your annotation, you first announce the title
and subtitle
properties are about to change:
[self willChangeValueForKey:@"title"];
[self willChangeValueForKey:@"subtitle"];
请注意,上面的代码被假定为在注释类中.
Note that the above code is assumed to be in the annotation class.
然后使用地理编码器中的信息更新注释.完成后:
Then update the annotation with information from the geocoder. When you are done:
[self didChangeValueForKey:@"subtitle"];
[self didChangeValueForKey:@"title"];
请注意didChangeValueForKey:
的顺序已更改,因为它们需要正确嵌套,有点像HTML标记.
Note the order changed for didChangeValueForKey:
as these need to be nested properly, somewhat like HTML tags.
这对于coordinate
属性也适用,这将导致销移动.
This also works for the coordinate
property, that will cause the pin to move.
这篇关于iPhone-在mapkit中更新注释字幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!