Reputation: 742
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 ?
Upvotes: 0
Views: 1106
Reputation: 323
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]); }
}];
Upvotes: 1