Ios 尝试对地址进行地理编码并获取kCLErrorGeocodeFoundNoResult
因此,我尝试对地址进行地理编码,当有人键入“asdfsfdsf”时,它会抛出一个错误Ios 尝试对地址进行地理编码并获取kCLErrorGeocodeFoundNoResult,ios,objective-c,clgeocoder,Ios,Objective C,Clgeocoder,因此,我尝试对地址进行地理编码,当有人键入“asdfsfdsf”时,它会抛出一个错误 "kCLErrorGeocodeFoundNoResult" 如何捕捉错误,使其不会向用户显示难看的弹出窗口(即上面的错误) -(void)geocodePinAddress:(NSString *)address withBlock:(void (^)(CLLocationCoordinate2D coord))block { CLGeocoder* gc = [[CLGeocoder alloc] in
"kCLErrorGeocodeFoundNoResult"
如何捕捉错误,使其不会向用户显示难看的弹出窗口(即上面的错误)
-(void)geocodePinAddress:(NSString *)address withBlock:(void (^)(CLLocationCoordinate2D coord))block {
CLGeocoder* gc = [[CLGeocoder alloc] init];
__block CLLocationCoordinate2D coord;
[gc geocodeAddressString:address completionHandler: ^(NSArray *placemarks, NSError *error) {
// Check for returned placemarks
if (placemarks && placemarks.count > 0) {
CLPlacemark* mark = [placemarks objectAtIndex:0];
coord = mark.location.coordinate;
block(coord);
}
}];
}
如果发生错误,为什么不直接显示消息
- (void)geocodePinAddress:(NSString *)address withBlock:(void (^)(CLLocationCoordinate2D coord))block {
CLGeocoder *gc = [[CLGeocoder alloc] init];
__block CLLocationCoordinate2D coord;
[gc geocodeAddressString:address completionHandler: ^(NSArray *placemarks, NSError *error) {
// if there was some error geocoding
if (error) {
// display whatever message you want, however you want, here
return;
}
// Check for returned placemarks
if (placemarks && placemarks.count > 0) {
CLPlacemark* mark = [placemarks objectAtIndex:0];
coord = mark.location.coordinate;
block(coord);
}
}];
}
我想展示我自己的信息,帮助他们理解他们做错了什么。“kCLErrorGeocodeFoundNoResult”不能帮助用户反馈他们做错了什么。对,所以写下你自己的消息并展示出来。你知道如何使用UIAlertView吗?我知道如何显示alertview。我需要知道如何防止iOS SDK出现自己的漏洞。iOS正在生成自己的流行音乐,我想阻止它出现。据我所知,它不应该出现,我以前从未见过。你确定没有这样的代码吗?我使用的库正在弹出它。谢谢。这是可行的,但是仍然会出现iOS错误。有没有一种方法可以使用try-catch块来防止iOS弹出消息?
Here is how you can handle geocoder domain errors :
if(placemarks.count > 0)
{
CLPlacemark *placemark = [placemarks objectAtIndex:0];
self.outputLabel.text = placemark.location.description;
}
else if (error.domain == kCLErrorDomain)
{
switch (error.code)
{
case kCLErrorDenied:
self.outputLabel.text = @"Location Services Denied by User";
break;
case kCLErrorNetwork:
self.outputLabel.text = @"No Network";
break;
case kCLErrorGeocodeFoundNoResult:
self.outputLabel.text = @"No Result Found";
break;
default:
self.outputLabel.text = error.localizedDescription;
break;
}
}