简体   繁体   English

发出前向地理编码多个地址

[英]Issue forward-geocoding multiple addresses

I am connecting to a remote web service which basically returns an XML back. 我正在连接到一个基本上返回XML的远程Web服务。 I am then parsing that XML into a Property object (think real state sort of thing) 然后我将该XML解析为Property对象(想想真实的状态)

But now, the web service returns a postal code for each property alone. 但现在,Web服务仅返回每个属性的邮政编码。 It does not provide a coordinate which is what I need to place an annotation in the map. 它没有提供我需要在地图中放置注释的坐标。 I am able to geocode an address provided a postal code. 我能够为邮政编码提供地址代码。 However, my problem is it is not allowing me to do multiple requests 但是,我的问题是它不允许我做多个请求

Here's my code 这是我的代码

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

For some reason it's just geocoding 1 property. 出于某种原因,它只是对1个属性进行地理编码。 Is not going through the loop accordingly. 不会相应地循环。

Any ideas folks? 有什么想法吗?

Use this on your Forward Geo Function. 在前向地理功能上使用此功能。 geocoder needs to be release and initialized again to start a new address, hope this helps. 地理编码器需要再次发布和初始化以启动新地址,希望这会有所帮助。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM