1

I am using Mapkit using objective c, i want to show "Error alert" on map. When Internet working, its working fine but When Internet not working properly then its showing automatically on log "request time out" with out calling "mapViewDidFailLoadingMap" delegate method.

Code Here:

- (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);
}

Showing Error:

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."}

Prashant
  • 81
  • 9

2 Answers2

1

I would test for a valid internet connection before you load mapKit. Check out this thread on how to do this.

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

Community
  • 1
  • 1
0

There is no issue in the code. I guess the simulator internally is not able to connect to the internet. Try connecting to some other wifi connection and test internet connection before you load MapView.

Check internet connection as :

#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;
}

You can also try resetting simulator as

iOS Simulator -> Reset Content and Settings

iAhmed
  • 5,786
  • 2
  • 23
  • 31
  • Thanks buddy, i know SCNetworkReachability but why "mapViewDidFailLoadingMap" delegate not working? – Prashant May 27 '15 at 09:18
  • Your loading location is failed for which you are getting this network error. if it gets location then will try to load on map. In case of failure in loading location on map , it will go inside "mapViewDidFailLoadingMap". – iAhmed May 27 '15 at 09:36