如何以编程方式打开调用MKAnnotationView? (iPhone,MapKit) [英] How to open call out MKAnnotationView programmatically? (iPhone, MapKit)
问题描述
我想以编程方式打开 MKPinAnnotationView
的标注。例如,我在地图上放了10个针脚,想要打开离我最近的一个针脚。我该怎么做呢?
I want to open up the callout for an MKPinAnnotationView
programmatically. Eg I drop 10 pins on the map, and want to open up the one closest to me. How would I go about doing this?
Apple为 MKAnnotationView的
指定了'selected'参数,但不鼓励设置直接(这不起作用,尝试过)。
Apple has specified the 'selected' parameter for MKAnnotationView's
, but discourages setting it directly (this doesn't work, tried it).
其余的 MKAnnotationView
只有一个setHighlighted( 同一个故事),可以 ShowCallout
方法..
For the rest MKAnnotationView
only has a setHighlighted (same story), and can ShowCallout
method..
任何提示,如果这是可能吗?
Any hints if this is possible at all?
推荐答案
在你的mapViewController中创建一个动作方法:
In your mapViewController create an action method:
- (void)openAnnotation:(id)annotation
{
//mv is the mapView
[mv selectAnnotation:annotation animated:YES];
}
然后,您可以根据当前位置确定最接近的注释,遍历数组中可用的注释。
You can then determine the closest annotation based on current location and walking the annotations available in the array.
[mv annotations];
计算出最接近的注释后,请致电:
Once the closest annotation is calculated, call:
[self openAnnotation:closestAnnotation];
mapView应自动滚动以将注释放在显示区域的中心。
The mapView should scroll automatically to place your annotation in the center of the display area.
这篇关于如何以编程方式打开调用MKAnnotationView? (iPhone,MapKit)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!