我有一系列国家名称,我想获取它们的坐标并存储到另一个数组中。在这个函数之后,我的经度和纬度数组仍然是空的。你知道这里有什么问题吗?我无法理解。
我的代码是:
- (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]);
}