我正在使用以下类创建一个带有地图和注释的视图:
#import <Foundation/Foundation.h>
#import <MapKit/MapKit.h>
@interface ContactDetailAnnotation : NSObject <MKAnnotation>
- (id) initWithLatitude:(CLLocationDegrees) lat longitude:(CLLocationDegrees) lng;
- (id) initWithCoordinate:(CLLocationCoordinate2D) coordinateArg;
@property (unsafe_unretained) CLLocationDegrees latitude;
@property (unsafe_unretained) CLLocationDegrees longitude;
@property (unsafe_unretained, nonatomic) CLLocationCoordinate2D coordinate;
@end
问题在于方法:
- (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation
用来绘制我的点没有被触发。如果我使用
self.myMap.showsUserLocation = TRUE;
该方法已触发,因此问题必须在我创建的类中。
我的.m
#import "ContactDetailAnnotation.h"
@implementation ContactDetailAnnotation
@synthesize latitude = _latitude, longitude = _longitude, coordinate = _coordinate;
- (id) initWithCoordinate:(CLLocationCoordinate2D) coordinateArg
{
self.coordinate = coordinateArg;
return self;
}
- (id) initWithLatitude:(CLLocationDegrees)lat longitude:(CLLocationDegrees)lng
{
self.latitude = lat;
self.longitude = lng;
return self;
}
- (CLLocationCoordinate2D) coordinate
{
CLLocationCoordinate2D coord = {self.latitude,
self.longitude};
return coord;
}
@end