iPhone:MKMapView和多针

时间:2012-03-14 19:06:35

标签: iphone

我想在MKMapView中为我的程序中的“运动”类别显示多个引脚。有人可以指导我如何在MKMapView中显示距离当前位置20英里的“体育”地方的多针?

感谢。

1 个答案:

答案 0 :(得分:0)

创建注释对象并将其添加到地图中。我称它们为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];