【问题标题】:Showing MapKit "Map loading error" in Objective C在Objective C中显示MapKit“地图加载错误”
【发布时间】:2015-05-27 07:51:18
【问题描述】:

我正在使用目标 c 使用 Mapkit,我想在地图上显示“错误警报”。 当互联网工作时,它工作正常,但当互联网工作不正常时,它会自动显示在日志“请求超时”而不调用“ma​​pViewDidFailLoadingMap”委托方法。

代码在这里:

- (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] 无法确定 当前国家代码:Error Domain=NSURLErrorDomain Code=-1001 "The 请求超时。” UserInfo=0x19d80290 {NSErrorFailingURLStringKey=http://gsp1.apple.com/pep/gcc, NSErrorFailingURLKey=http://gsp1.apple.com/pep/gcc, NSLocalizedDescription=请求超时。, NSUnderlyingError=0x17e877a0 "请求超时。"}

【问题讨论】:

    标签: ios objective-c iphone ipad ios8


    【解决方案1】:

    我会在您加载 mapKit 之前测试有效的互联网连接。查看此线程以了解如何执行此操作。

    How to check for an active Internet connection on iOS or OSX?

    【讨论】:

      【解决方案2】:

      代码中没有问题。我猜模拟器内部无法连接到互联网。在加载 MapView 之前尝试连接到其他一些 wifi 连接并测试互联网连接。

      检查互联网连接为:

      #import <SystemConfiguration/SCNetworkReachability.h>
      
      
      +(bool)isNetworkAvailable
      {
         SCNetworkReachabilityFlags flags;
         SCNetworkReachabilityRef address;
         address = SCNetworkReachabilityCreateWithName(NULL, "www.apple.com" );
         Boolean success = SCNetworkReachabilityGetFlags(address, &flags);
         CFRelease(address);
      
      bool canReach = success
                      && !(flags & kSCNetworkReachabilityFlagsConnectionRequired)
                      && (flags & kSCNetworkReachabilityFlagsReachable);
      
         return canReach;
      }
      

      您也可以尝试将模拟器重置为

      iOS 模拟器 -> 重置内容和设置

      【讨论】:

      • 谢谢哥们,我知道 SCNetworkReachability 但为什么“mapViewDidFailLoadingMap”委托不起作用?
      • 您的加载位置失败,您收到此网络错误。如果它获得位置,那么将尝试在地图上加载。如果在地图上加载位置失败,它将进入“mapViewDidFailLoadingMap”。
      猜你喜欢
      • 1970-01-01
      • 2013-09-08
      • 2014-08-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多