MapAnnotation.h
#import <Foundation/Foundation.h>
#import <MapKit/MKAnnotation.h>
@interface MapAnnotation : NSObject <MKAnnotation>
@property(nonatomic, assign) CLLocationCoordinate2D coordinate;
@property(nonatomic, copy) NSString *title;
@property(nonatomic, copy) NSString *subtitle;
-(id)initWithCoordinate:(CLLocationCoordinate2D)Region withtitle:(NSString *)Title andSubTitle:(NSString *)SubTitle ;
MapAnnotation.m
@implementation EventAtPlacesAnnotation
@synthesize title = _title, subtitle = _subtitle,coordinate = _coordinate;
-(id)initWithCoordinate:(CLLocationCoordinate2D)Region withtitle:(NSString *)Title andSubTitle:(NSString *)SubTitle
{
self = [super init];
if(self){
_title = Title;
_subtitle = SubTitle;
_coordinate = Region;
}
return self;
}
从您使用地图视图的类中分配值
CLLocationCoordinate2D newCoordinate = CLLocationCoordinate2DMake(40.56, 90.83);
MapAnnotation *firstannotation = [[MapAnnotation alloc]initWithCoordinate:newCoordinate withtitle:@"Place 1" andSubTitle:@"Near To empire state"];
[myMapview addAnnotation:firstannotation];