在做团购项目,使用了mapkit,不过它显示的都是中文拼音,当我获取的地理位置,发送请求后,因为city = Guangzho,直接报下面的错误: 2015-08-12 20:35:28.222 团[44689:2380177] Error Domain=Parameter value is invalid: city. (请求参数值无效: city) Code=10011 "The operation couldn’t be completed. (Parameter value is invalid: city. (请求参数值无效: city) error 10011.)" UserInfo=0x7c29af70 {errorMessage=Parameter value is invalid: city. (请求参数值无效: city), errorCode=10011} 2015-08-12 20:35:29.667 GATuan[44689:2380177] params : { longitude = 113.3684551059959, latitude = 23.11926916664753, city = Guangzho, radius = 500 }
恩,找到了解决方法了。
#pragma mark - MKMapViewDelegate
//当用户的位置更新了就会调用
-(void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation{
[self.coder reverseGeocodeLocation:userLocation.location completionHandler:^(NSArray *placemarks, NSError *error) {
if (error || placemarks.count == 0) {
return ;
}
CLPlacemark *pm = [placemarks firstObject];
NSLog(@"pm %@",pm.locality);
//城市,这个city是拼音的地名
NSString *city = pm.locality ? pm.locality : pm.addressDictionary[@"state"];
//转换成小写
city = city.lowercaseString;
//定义过滤器
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"pinYin contains %@",city];
//self.cities:存储了所以的城市信息,从这个数组中搜索
GACity *gaCity= [[self.cities filteredArrayUsingPredicate:predicate] firstObject];
NSLog(@"city :%@",gaCity.name);
self.city = gaCity.name;
}];
}
请问你的self.cities是什么样的。能发给我吗,783513920@qq.com