0

我正在像这样在地图视图中添加多个标记,

markers = [jsonDict objectForKey:key];
            for (id k in markers) {

                if ([k isEqualToString:@"latitude"]) {

                    mlat = [markers objectForKey:k];
                    dlat = [mlat doubleValue];
                }

                else if ([k isEqualToString:@"longitude"]) {

                    mlng = [markers objectForKey:k];
                    dlng = [mlng doubleValue];
                }


                else if ([k isEqualToString:@"file"]){
                    murl = [markers objectForKey:k];
                }

                else if ([k isEqualToString:@"comment"]){
                    mcomment = [markers objectForKey:k];
                }

            }
            annotationCoord.latitude = dlat;
            annotationCoord.longitude = dlng;
            MKPointAnnotation *annotationPoint = [[MKPointAnnotation alloc] init];
            annotationPoint.coordinate = annotationCoord;
            [self.navimap addAnnotation:annotationPoint];

comment现在,我想filedidSelectAnnotationView. 如果有人在这方面帮助我,将不胜感激。

4

1 回答 1

0

You should create a custom annotation class and use it rather than MKPointAnnotation:

#import <MapKit/MapKit.h>

@interface Marker : NSObject <MKAnnotation>

@property (nonatomic, copy) NSString *title;
@property (nonatomic, copy) NSString *subtitle;
@property (nonatomic) CLLocationCoordinate2D coordinate;
@property (nonatomic,copy) NSString* url;
@property (nonatomic,copy) NSString* comment;

@end

You would then implement didSelectAnnotationView like this:

-(void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view
{        
    if ([view.annotation isKindOfClass:[Marker class]]) {
        Marker* marker = view.annotation;
        NSLog(@"selected marker %@", marker);
    }
}
于 2013-03-18T10:50:25.573 回答