0

Hi am using this method to get the coordinates and add a pin to the map view for one post code

-(void)myMapview
{
    //sitePC is an Array with the Post code location
    NSString *addressString = [self.sitePC valueForKey:@"sitePC"];

    CLGeocoder *geocoder = [[CLGeocoder alloc] init];

    [geocoder geocodeAddressString:addressString completionHandler:^(NSArray *placemarks, NSError *anError)

     { for(CLPlacemark *placemark in placemarks) {
             NSLog(@"Placemark: %@",placemark);

             MKPointAnnotation *pa = [[MKPointAnnotation alloc] init];

             pa.coordinate = placemark.location.coordinate;
             pa.title = [self.sitePC valueForKey:@"siteName"];
             [self.mapview addAnnotation:pa];

         }          if(anError)
         { NSLog(@"Error: %@",[anError description]); }         
     }];
}

but now the sitePC array hold 10 post codes to process, I read the Documents for CLGeocoder and I know I can only send one request at the time.

my question is how do I send only one request at the time , for each postcode ?

HernandoZ
  • 742
  • 2
  • 12
  • 24

1 Answers1

1

You can make an Array for annotations and Add that annotation array on MapView . Hope following changes in code will help you.

NSString *addressString = [self.sitePC valueForKey:@"sitePC"];

CLGeocoder *geocoder = [[CLGeocoder alloc] init];

[geocoder geocodeAddressString:addressString completionHandler:^(NSArray *placemarks, NSError *anError)

 { 
    NSMutableArray *pointsArray = [[NSMutableArray alloc]init]
     for(CLPlacemark *placemark in placemarks) {
         NSLog(@"Placemark: %@",placemark);

         MKPointAnnotation *pa = [[MKPointAnnotation alloc] init];

         pa.coordinate = placemark.location.coordinate;
         pa.title = [self.sitePC valueForKey:@"siteName"];
         [pointsArray addObject:pa];
     }  
     [self.mapview addAnnotations:pointsArray];
  if(anError)
     { NSLog(@"Error: %@",[anError description]); }         
 }];
indu
  • 323
  • 2
  • 18
  • I get an error - 2012-11-14 12:38:57.987 SRMIpadTest2[32594:3c03] -[__NSArrayI length]: unrecognized selector sent to instance 0x8912000 2012-11-14 12:38:57.988 SRMIpadTest2[32594:3c03] *** Terminating app due to uncaught exception - as soon as the geocoder is call. – HernandoZ Nov 14 '12 at 12:39
  • Once check with dummy Address say NSString *addressString = @"1 Infinite Loop, Cupertino, CA" and comment this line pa.title = [self.sitePC valueForKey:@"siteName"]; and then run.. And let me know if it is still crashing. – indu Nov 14 '12 at 12:57