在地图视图上显示多个地图 annotations/coordinates

Show multiple map annotations/coordinates on mapview

我正在使用以下代码将数组 (responseObject) 中的地址显示为地图视图上的注释。它有效,并且从我的位置字符串中成功删除了 pin,但是它只显示了添加到数组中的最新地址的 pin。我如何更改我的代码,以便它在地图上显示阵列中所有地址的引脚,而不仅仅是最近的一个?如果这是一个新问题,我们深表歉意。谢谢!

viewcontroller.m

 NSMutableDictionary *viewParams = [NSMutableDictionary new];
    [viewParams setValue:@"u000" forKey:@"view_name"];
    [DIOSView viewGet:viewParams success:^(AFHTTPRequestOperation *operation, id responseObject) {

        self.addressData = [responseObject mutableCopy];

        NSString *location = self.addressData[0][@"address"];

        CLGeocoder *geocoder = [[CLGeocoder alloc] init];
    [geocoder geocodeAddressString:location
                 completionHandler:^(NSArray* placemarks, NSError* error){
                    if (placemarks && placemarks.count > 0) {
                         CLPlacemark *topResult = [placemarks objectAtIndex:0];
                         MKPlacemark *placemark = [[MKPlacemark alloc] initWithPlacemark:topResult];

                         MKCoordinateRegion region = self.mapView.region;
                    //     region.center = placemark.region.center;
                         region.span.longitudeDelta /= 8.0;
                         region.span.latitudeDelta /= 8.0;

                        [self.mapView setRegion:region animated:YES];
                      [self.mapView addAnnotation:placemark];

                        MKPointAnnotation *point = [[MKPointAnnotation alloc] init];
                        point.coordinate = placemark.coordinate;
                        point.title = self.addressData[0][@"users_name"];
                        point.subtitle = self.addressData[0][@"userbio"];

                        [self.mapView addAnnotation:point];

您只访问了一个对象?

NSString *location = self.addressData[0][@"address"];

已编辑

  1. 我认为你应该处理你的数据,与你的观点分开。即在地图视图委托的 mapView:viewForAnnotation: 方法中实现 geocoder 相关代码。然后你应该能够一个一个地创建注释并对所有注释使用 [self.mapView addAnnotations]
  2. 对于您的代码,我相信它的灵感来自 this answer,您应该能够通过类似

    的方式遍历所有位置地址
    for (NSMutableDictionary *loc in self.addressData) {
        NSString *loc = location[@"address"];
    
        CLGeocoder *geocoder = [[CLGeocoder alloc] init];
        ......
    }
    

    如果 Objective C.

  3. 的语法有误请见谅