Answers
你说的应该是用的中央气象台API所需要的城市代码吧。
先把代码表存储到一个plist文件中
然后:
NSString *plistPath = [[NSBundle mainBundle] pathForResource:@"cityList" ofType:@"plist"];
_areaidDictionary = [[NSDictionary alloc] initWithContentsOfFile:plistPath];
areaidDictionary是区域id的字典
之后用
- (void)transToareaidfromLocation:(CLLocation *)location {
self.areaid = nil;
self.geocoder = [[CLGeocoder alloc] init];
[self.geocoder reverseGeocodeLocation:location
completionHandler:^(NSArray *placemarks, NSError *error) {
if (error == nil && [placemarks count] > 0) {
CLPlacemark *placemark = [placemarks objectAtIndex:0];
self.city = placemark.locality;
self.areaid = self.areaidDictionary[self.city];
NSLog(@"city:%@",self.city);
NSLog(@"areaid:%@",self.areaid);
} else if (error == nil && [placemarks count] == 0) {
NSLog(@"No location results were returned");
} else if (error != nil) {
NSLog(@"An error occurred:%@",error.description);
}
}];
}
在反地理编码的同时,利用字典找到areaid。
areaid就是你要的城市代码。
sadddd
answered 10 years, 3 months ago