简体   繁体   English

MKAnnotation-添加网址

[英]MKAnnotation - adding url

I'm working through mayurbirari's sample code to generate a mapkit view, I want to add a url to the popup. 我正在通过mayurbirari的示例代码来生成mapkit视图,我想在弹出窗口中添加一个URL。 I've tried to understand the apple reference to subclass but TBH it just isnt going it. 我试图理解苹果对子类的引用,但是TBH只是没有用。

I need to create a subclass that can have additional variable added to it as MKANNOTATION is core file and cannot be changed - therefore how do I do it?? 我需要创建一个可以添加其他变量的子类,因为MKANNOTATION是核心文件,无法更改-因此,我该怎么做? I'm confused about how to set it up. 我对如何设置感到困惑。

the code can be found here --> http://mayurbirari.wordpress.com/2011/02/07/how-to-access-mkmapkit-in-iphone/ 可以在这里找到代码-> http://mayurbirari.wordpress.com/2011/02/07/how-to-access-mkmapkit-in-iphone/

if someone could show me the example of the subclass with URL added to it, it would probably sink in, but all the examples I've found seem to be over complicated. 如果有人可以向我展示添加了URL的子类示例,则该示例可能陷入其中,但是我发现的所有示例似乎都过于复杂。

MKAnnotation is a protocol that you have to adopt in your own class -- whichever class you're using to represent an annotation object. MKAnnotation是您必须在自己的类中采用的协议,无论您要使用哪种协议来表示注释对象。 This is often a class that's part of your data model. 这通常是数据模型中一部分的类。 For example, you might have a Person class and want to show instances of Person on a map. 例如,您可能有一个Person类,并且想要在地图上显示Person的实例。 You'd adopt MKAnnotation in Person. 您将亲自采用MKA注释。 It's easy to use properties for this: 使用属性很容易做到这一点:

@interface Person : NSObject <MKAnnotation>
{
   //...
}
//...
@property (nonatomic, readonly) CLLocationCoordinate2D coordinate;
@property (nonatomic, retain) NSString *title;
@property (nonatomic, retain) NSString *subtitle;
@end

And then implement the methods from MKAnnotation in your class: 然后在您的类中实现MKAnnotation中的方法:

@implementation Person

@synthesize coordinate;
@synthesize title;
@synthesize subtitle;

//...various methods of Person...

@end

Now you can add instances of Person to the map as annotations. 现在,您可以将Person的实例作为注释添加到地图上。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM