1.
MapKit.framework
라이브러리를 추가한다.
2.
#import <Foundation/Foundation.h>
#import <MapKit/MapKit.h>
@interface Annotation : NSObject <MKAnnotation> {
double dLatitude;
double dLongitude;
NSString *sTitle;
NSString *sSubtitle;
}
@property (nonatomic, readonly) CLLocationCoordinate2D coordinate;
- (id)initWithLatitude:(double)latitude
longitude:(double)longitude
title:(NSString*)title
subtitle:(NSString*)subtitle;
- (NSString *)title;
- (NSString *)subtitle;
@end
3.
#import "Annotation.h"
@implementation Annotation
- (CLLocationCoordinate2D) coordinate {
CLLocationCoordinate2D captureCoord;
captureCoord.latitude = dLatitude;
captureCoord.longitude = dLongitude;
return captureCoord;
}
- (id)initWithLatitude:(double)latitude
longitude:(double)longitude
title:(NSString*)title
subtitle:(NSString*)subtitle {
dLatitude = latitude;
dLongitude = longitude;
sTitle = title;
sSubtitle = subtitle;
return self;
}
- (NSString *)title {
return sTitle;
}
- (NSString *)subtitle {
return sSubtitle;
}
@end
4.
Annotation *a = [[Annotation alloc] initWithLatitude:37.523 longitude:127.048 title:@"VINYL" subtitle:@"company"];
[self.mapView addAnnotation:a];