我在地图视图中添加多个标记,如下所示,
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
中的每个标记获取“file
”和“didSelectAnnotationView
”的值。如果有人帮助我,我将不胜感激。
答案 0 :(得分:0)
您应该创建一个自定义注释类并使用它而不是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
然后您可以像这样实施didSelectAnnotationView
:
-(void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view
{
if ([view.annotation isKindOfClass:[Marker class]]) {
Marker* marker = view.annotation;
NSLog(@"selected marker %@", marker);
}
}