国名の配列があり、それらの座標を取得して別の配列に保存したいと考えています。この関数の後、経度と緯度の配列はまだ空のままです。ここで何が問題なのか分かりますか?理解できません。
私のコードは:
- (void)geocode {
NSString *strcountry=[[NSString alloc]init];
countryLati=[[NSMutableArray alloc]init];
countryLongi=[[NSMutableArray alloc]init];
countryName =[NSMutableArray arrayWithObjects:@"Bahrain",@"Bangladesh",@"Bhutan",@"China",@"Georgia",@"Hong Kong",nil ];
int count=[countryName count];
for(int i=0;i<count;i++)
{
strcountry=[countryName objectAtIndex:i];
[SVGeocoder geocode:strcountry
completion:^(NSArray *placemarks, NSHTTPURLResponse *urlResponse, NSError *error) {
//NSLog(@"placemarks = %@", placemarks);
CLPlacemark *place = [placemarks objectAtIndex:0];
CLLocation *location = place.location;
CLLocationCoordinate2D coord = location.coordinate;
NSString *tempLati=[[NSString alloc]initWithFormat:@"%g",coord.latitude];
NSString *tempLongi=[[NSString alloc]initWithFormat:@"%g",coord.longitude];
NSLog(@"-------------------------");
NSLog(@"Country : %@",strcountry);
NSLog(@"Latitude : %@ ",tempLati);
NSLog(@"Longitude : %@ ",tempLongi);
[countryLati addObject:tempLati];
[countryLongi addObject:tempLongi];
}];
}
NSLog(@"%d",[countryName count]);
NSLog(@"%d ",[countryLati count]);
NSLog(@"%d ",[countryLongi count]);
}