ios - 在 Objective C 中显示 MapKit "Map loading error"

标签 ios objective-c iphone ipad ios8

我正在使用 Mapkit 和 objective-c ,我想在 map 上显示“错误警报”。 当 Internet 工作时,它工作正常,但当 Internet 工作不正常时,它会自动在日志上显示“请求超时”,而无需调用“ma​​pViewDidFailLoadingMap”委托(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/

相关文章:

ios - 在 iOS 7 中撰写邮件 : Assertion failure in -[MFComposeSubjectView layoutSublayersOfLayer:]

iPhone OpenGLES 2.0 文本纹理带有奇怪的边框(不是描边)问题

iphone - XCode 4.3.2 中的自定义字体

php - 如何国际化/本地化您的 FCM 推送通知,尤其是主题?

ios - 为什么纬度和经度在 ios 9 中显示为零?

ios - Braintree:在沙盒模式下创建或更新具有 CVV 验证的客户时出现授权错误

ios - 如何从字符串中获取 NSDate

ios - 通过在 iOS swift 中排序两个值来查询 firebase 数据库

ios - 如何在 iOS 中为 UISearchBar 背景 View 应用圆角半径?

iphone - 我如何通过xcode搜索iphone中的所有声音文件