2010-07-02 79 views

回答

1

你可以使用下面的示例代碼;


// .h 
#import <Foundation/Foundation.h> 
#import <MapKit/MapKit.h> 
@interface AddressAnnotation : NSObject<MKAnnotation> { 
    CLLocationCoordinate2D coordinate; 
    NSString *title; 
    NSString *subtitle; 
    MKPinAnnotationColor pinColor; 
} 
@property (nonatomic,retain) NSString *title; 
@property (nonatomic,retain) NSString *subtitle; 
@property (nonatomic, assign) MKPinAnnotationColor pinColor; 
@end 

// .m 
#import "AddressAnnotation.h" 

@implementation AddressAnnotation 
@synthesize coordinate; 
@synthesize title; 
@synthesize subtitle; 
@synthesize pinColor; 
- (NSString *)subtitle{ 
    return subtitle; 
} 
- (NSString *)title{ 
    return title; 
} 
-(id)initWithCoordinate:(CLLocationCoordinate2D) c{ 
    coordinate=c; 
    return self; 
} 
@end 

currentLocation.latitude = latitudeValue; 
currentLocation.longitude = longitudeValue; 
AddressAnnotation *addAnnotation = [[AddressAnnotation alloc] initWithCoordinate:currentLocation]; 
[addAnnotation setTitle:@"Title"]; 
[addAnnotation setPinColor:MKPinAnnotationColorGreen]; 
[map addAnnotation:addAnnotation]; 
[addAnnotation release]; 

otherLocation.latitude = latitudeValue; 
otherLocation.longitude = longitudeValue; 
addAnnotation = [[AddressAnnotation alloc] initWithCoordinate:otherLocation]; 
[addAnnotation setTitle:@"otherTitle"]; 
[map addAnnotation:addAnnotation]; 
[addAnnotation release]; 
相關問題