iRSSの日記

はてなダイアリーiRSSの日記の続き

MKMapView上の任意のAnnotationを表示する

かきかけです。

@interface MyMapAnnotationView : MKAnnotationView {
}
@end

//以下雰囲気です。以下コードでの動作確認していません。
@interface MyMapViewController : UIViewController <MKMapViewDelegate>
@property (nonatomic, string) MKMapView *mapView;

@end

@implementation MyMapViewController

- (void)forcusPin:(NSInteger)spotID

    NSArray *anns = self.mapView.annotations;
    
    int i;
    for (i = 0; i < [anns count]; i++) {
        id ann = [anns objectAtIndex:i];
        if([[ann class] isEqualToString:@"MyMapAnnotationView"]){
            MyMapAnnotationView *annotation = [anns objectAtIndex:i];
            NSUInteger annID = annotation.annotationID;
            if(annID == spotID){
                [self.mapView selectAnnotation:annotation animated:YES];
                [self.mapView setCenterCoordinate:annotation.coordinate animated:YES];
                
            }
        }
    }
@end