开发者

iPhone - Updating Annotation subtitle in mapkit

开发者 https://www.devze.com 2023-02-27 08:02 出处:网络
I have a custom placemark with title and subtitle. The subtitle is actually displaying the address of the dropped pin using the reverse geocoder.

I have a custom placemark with title and subtitle. The subtitle is actually displaying the address of the dropped pin using the reverse geocoder.

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

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.

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 di开发者_StackOverflow中文版splay the annotation without the address details and update it when it gets the information from the reverse geocoder.

Any suggestions?

Thanks in advance


MKMapView observes changes its annotations via KVO. Therefore if you update your annotation's properties in a KVO compliant manner, it should Just Work.

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"];

Note the order changed for didChangeValueForKey: as these need to be nested properly, somewhat like HTML tags.

This also works for the coordinate property, that will cause the pin to move.


I'd place the annotation, keep a reference to it in a property, then when your reverse geocoder calls back use the reference to the annotation and update its properties.

0

精彩评论

暂无评论...
验证码 换一张
取 消