我想在MKMapView中为我的程序中的"体育"类别位置显示多个pin。有人能指导我如何在距离当前位置约20英里的"体育"场所的MKMapView中显示多针吗?
谢谢。
创建注释对象并将它们添加到映射中。我称之为LocalAnnotation。
LocalAnnotation.h:
@interface LocationAnnotation : NSObject <MKAnnotation>
{
CLLocationCoordinate2D coordinate;
NSString *title;
NSString *subtitle;
}
@property (nonatomic) CLLocationCoordinate2D coordinate;
@property (nonatomic, copy) NSString *title;
@property (nonatomic, copy) NSString *subtitle;
-initWithCoordinate:(CLLocationCoordinate2D)inCoord;
@end
LocalAnnotation.m:
#import "locationAnnotation.h"
@implementation LocationAnnotation
@synthesize coordinate;
@synthesize title;
@synthesize subtitle;
-init
{
return self;
}
-initWithCoordinate:(CLLocationCoordinate2D)inCoord
{
coordinate = inCoord;
return self;
}
@end
在使用地图的方法中:
//erase all annotations
[self.geoMap removeAnnotations:[self.geoMap annotations]]; //geoMap is an MKMapView object.
//Set the pin
CLLocationCoordinate2D newCoordinate;
newCoordinate.latitude = (CLLocationDegrees) [exifGeoLatitudeNumeric doubleValue]; //exifGeoLatitudeNumeric is a NSNumber representing a coordinate in the format +/-23.5435423
newCoordinate.longitude = (CLLocationDegrees) [exifGeoLongitudeNumeric doubleValue]; //exifGeoLongitudeNumeric is a NSNumber representing a coordinate in the format +/y23.5435423
LocationAnnotation *newAnnotation = [[LocationAnnotation alloc] initWithCoordinate:newCoordinate];
[self.geoMap addAnnotation:newAnnotation];