为多个标记选择注释

添加了多了个注释在地图view中:

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

现在我要获取didSelectAnnotationView中comment 和file对每个标记的的值。

不知道怎么实现?

ChatGPT尝试为您解答,仅供参考
你可以在 didSelectAnnotationView 函数中通过访问 annotation 属性来获取标记的信息。


你可以在你的 MKPointAnnotation 类中定义一个 comment 和 file 属性,并在创建标记时设置这些属性的值。这样,在选择标记时,你就可以使用这些属性获取标记的信息。


例如,你可以在创建标记时这样做:

MKPointAnnotation *annotationPoint = [[MKPointAnnotation alloc] init];
annotationPoint.coordinate = annotationCoord;
annotationPoint.comment = mcomment;
annotationPoint.file = murl;
[self.navimap addAnnotation:annotationPoint];

然后,在 didSelectAnnotationView 函数中,你可以访问标记的属性来获取信息:

- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view
{
    MKPointAnnotation *selectedAnnotation = (MKPointAnnotation *)view.annotation;
    NSString *comment = selectedAnnotation.comment;
    NSString *file = selectedAnnotation.file;
    // 这里你可以使用 comment 和 file 变量来获取标记的信息
}