iPhone:创建 MKAnnotation

发布于 2024-09-02 17:45:28 字数 134 浏览 1 评论 0原文

我可以创建 MKAnnotation,还是只读?我有坐标,但我发现使用 setCooperative 手动创建 MKAnnotation 并不容易。

有想法吗?

Can I create an MKAnnotation, or is it read only? I have coordinates, but I am not finding it easy to manually create an MKAnnotation with using setCoordinate.

Ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

俏︾媚 2024-09-09 17:45:28

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

如果您不想在注释标注上添加标题和副标题,则需要添加标题和副标题属性。

MKAnnotation is a protocol. So you need to write your own annotation object that implements this protocol. So your MyAnnotation header looks like:

@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;

and your implementation looks like (MyAnnotation.m):

- (id) initWithCoordinate:(CLLocationCoordinate2D)coord
{
    coordinate = coord;
    return self;
}

So to add your annotation to the map:

MyAnnotation * annotation = [[[MyAnnotation alloc] initWithCoordinate:coordinate] autorelease];
[self.mapView addAnnotation:annotation];

If you wan't a title and subtitle on the annotation callout, you need to add the title and subtitle properties.

子栖 2024-09-09 17:45:28

iPhone OS 4 中有一个新类 MKPointAnnotation,它是 MKAnnotation 协议的具体实现。

In iPhone OS 4 there is a new class MKPointAnnotation which is a concrete implementation of the MKAnnotation protocol.

撩人痒 2024-09-09 17:45:28

检查苹果 MapCallouts 项目。您需要的一切都在该文件中:
http://developer.apple.com/iphone/library/samplecode /MapCallouts/Introduction/Intro.html

Check apple MapCallouts project. Everything you need is in that file:
http://developer.apple.com/iphone/library/samplecode/MapCallouts/Introduction/Intro.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文