3

基本的に XML を返すリモート Web サービスに接続しています。次に、その XML を解析して Property オブジェクトにします (実際の状態のようなものを考えてください)。

しかし今では、Web サービスは各プロパティの郵便番号のみを返します。マップに注釈を配置するために必要な座標は提供されません。郵便番号を指定して住所をジオコーディングできます。ただし、私の問題は、複数のリクエストを実行できないことです

これが私のコードです

- (void)processProperties:(Property *)property {

    [geocoder geocodeAddressString:property.postalCode
                 completionHandler:^(NSArray* placemarks, NSError* error){
                     placemark = [placemarks lastObject];
                     for (CLPlacemark* aPlacemark in placemarks)
                     {
                         [sublet setLatitude:aPlacemark.location.coordinate.latitude];
                         [sublet setLongitude:aPlacemark.location.coordinate.longitude];  
                     }
                 }];
}


- (void)addAnnotations:(NSArray *)objects {
    CLLocationDegrees lat;
    CLLocationDegrees longitude;
    CLLocationCoordinate2D mCoords;
    NSString *fullAddress;

    // Add the annotations found nearby
    for (Property *property in objects) {

        [self processProperties:property];
        lat = property.latitude;
        longitude = property.longitude;

        fullAddress = [NSString stringWithFormat:@"%@ %@ %@", property.houseNumber, @" ", property.streetName];
        [self createAnnotationWithCoords:mCoords :fullAddress :[NSString stringWithFormat:@"$%.2f", property.rent]];
    }
    zoomLevel = 0.1;
    mCoords = CLLocationCoordinate2DMake(lat,longitude);
    MKCoordinateRegion region = MKCoordinateRegionMake(mCoords,MKCoordinateSpanMake(zoomLevel,zoomLevel));

   [self.mapView setRegion:region animated:YES];
}

何らかの理由で、1 つのプロパティをジオコーディングするだけです。それに応じてループを通過していません。

アイデアはありますか?

4

1 に答える 1

6

これを Forward Geo Function で使用します。新しい住所を開始するには、ジオコーダーを解放して再度初期化する必要があります。

- (void)processProperties:(Property *)property { 
CLGeocoder *geocoder = [[CLGeocoder alloc] init]; 
[geocoder geocodeAddressString:property.postalCode
             completionHandler:^(NSArray* placemarks, NSError* error){
                 placemark = [placemarks lastObject];
                 for (CLPlacemark* aPlacemark in placemarks)
                 {
                     [sublet setLatitude:aPlacemark.location.coordinate.latitude];
                     [sublet setLongitude:aPlacemark.location.coordinate.longitude];  
                 }
                 [geocoder release];
             }];
  }
于 2012-01-17T10:59:38.330 に答える