我正在使用 Mapkit 和 objective-c ,我想在 map 上显示“错误警报”。 当 Internet 工作时,它工作正常,但当 Internet 工作不正常时,它会自动在日志上显示“请求超时”,而无需调用“mapViewDidFailLoadingMap”委托(delegate)方法。
代码在这里:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
mapView.delegate=self;
mapView.showsUserLocation = YES;
[mapView setMapType:MKMapTypeStandard];
[mapView setZoomEnabled:YES];
[mapView setScrollEnabled:YES];
//[self activeCLLocation];
}
-(void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation
{
NSLog(@"user latitude==>%f",userLocation.location.coordinate.latitude);
NSLog(@"user longitude==>%f",userLocation.location.coordinate.longitude);
}
-(void)mapViewDidFailLoadingMap:(MKMapView *)mapView withError:(NSError *)error
{
NSLog(@"error map===>%@",error.description);
}
-(void)mapView:(MKMapView *)mapView didFailToLocateUserWithError:(NSError *)error
{
NSLog(@"error loc===>%@",error.description);
}
显示错误:
2015-05-27 12:51:57.624 EventLocator[1262:160081] Could not determine current country code: Error Domain=NSURLErrorDomain Code=-1001 "The request timed out." UserInfo=0x19d80290 {NSErrorFailingURLStringKey=http://gsp1.apple.com/pep/gcc, NSErrorFailingURLKey=http://gsp1.apple.com/pep/gcc, NSLocalizedDescription=The request timed out., NSUnderlyingError=0x17e877a0 "The request timed out."}
最佳答案
我会在您加载 mapKit 之前测试有效的互联网连接。查看此线程以了解如何执行此操作。
How to check for an active Internet connection on iOS or OSX?
关于ios - 在 Objective C 中显示 MapKit "Map loading error",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30476285/