2012-03-14 16 views
0

我想在MKMapView中爲我的程序中的「運動」類別位置顯示多個針腳。有人可以指導我如何在MKMapView中顯示多針距離當前位置20英里的「體育」地點?iPhone:MKMapView和多針腳

謝謝。

回答

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]; 
+0

你好,非常感謝你!我可以編碼改變圖釘圖像(而不是默認的紅色圖案),當點擊特定的圖釘時,我可以在小矩形視圖中顯示細節嗎? – Getsy 2012-03-15 03:01:39

+0

是的,你可以。我無法爲您提供示例代碼,因爲我自己還沒有完成。您將在此處找到適當記錄的詳細信息:https://developer.apple.com/library/ios/#documentation/MapKit/Reference/MapKit_Framework_Reference/_index.html – 2012-03-15 13:07:05