问题
I have implemented the MKAnnotation as below. I will put a lot of pins and the information for each of those pins are stored in an array. Each member of this array is an object whose properties will give the values for the title and subtitle of the pin. Each object corresponds to a pin. But how can I display these values for the pin when I click a pin??
@interface UserAnnotation : NSObject <MKAnnotation>
{
CLLocationCoordinate2D coordinate;
NSString *title;
NSString *subtitle;
NSString *city;
NSString *province;
}
@property (nonatomic, assign) CLLocationCoordinate2D coordinate;
@property (nonatomic, retain) NSString *title;
@property (nonatomic, retain) NSString *subtitle;
@property (nonatomic, retain) NSString *city;
@property (nonatomic, retain) NSString *province;
-(id)initWithCoordinate:(CLLocationCoordinate2D)c;
And .m is
@implementation UserAnnotation
@synthesize coordinate, title, subtitle, city, province;
- (NSString *)title
{
return title;
}
- (NSString *)subtitle
{
return subtitle;
}
- (NSString *)city
{
return city;
}
- (NSString *)province
{
return province;
}
-(id)initWithCoordinate:(CLLocationCoordinate2D)c
{
coordinate=c;
NSLog(@"%f,%f",c.latitude,c.longitude);
return self;
}
@end
回答1:
Ony two lines were added and all were done.
annView.canShowCallout = YES;
annView.calloutOffset = CGPointMake(-5, 5);
来源:https://stackoverflow.com/questions/3054374/how-to-get-the-title-and-subtitle-for-a-pin-when-we-are-implementing-the-mkannot