我可以创建一个MKAnnotation
,还是只读的?我有坐标,但我发现手动创建MKAnnotation
with using并不容易setCoordinate
。
想法?
我可以创建一个MKAnnotation
,还是只读的?我有坐标,但我发现手动创建MKAnnotation
with using并不容易setCoordinate
。
想法?
MKAnnotation是一个协议。所以你需要编写自己的注解对象来实现这个协议。所以你的 MyAnnotation 标头看起来像:
@interface MyAnnotation : NSObject<MKAnnotation> {
CLLocationCoordinate2D coordinate;
}
@property (nonatomic, readonly) CLLocationCoordinate2D coordinate;
// add an init method so you can set the coordinate property on startup
- (id) initWithCoordinate:(CLLocationCoordinate2D)coord;
你的实现看起来像(MyAnnotation.m):
- (id) initWithCoordinate:(CLLocationCoordinate2D)coord
{
coordinate = coord;
return self;
}
因此,要将注释添加到地图:
MyAnnotation * annotation = [[[MyAnnotation alloc] initWithCoordinate:coordinate] autorelease];
[self.mapView addAnnotation:annotation];
如果注释标注上没有标题和副标题,则需要添加标题和副标题属性。
在 iPhone OS 4 中有一个新的类 MKPointAnnotation,它是 MKAnnotation 协议的具体实现。
检查苹果 MapCallouts 项目。您需要的一切都在该文件中:http: //developer.apple.com/iphone/library/samplecode/MapCallouts/Introduction/Intro.html