0

I am using CLLocationManager to grab the location.Though I have GPS settings working on my device, it shows the status popup randomly which is defined in didFailWithError

Error I am getting is,

Error Domain=kCLErrorDomain Code=0 "The operation couldn’t be completed. (kCLErrorDomain error 0.)"

-(void) startGettingCurrentLocation {

    CLLocationManager *locationManager=[[CLLocationManager alloc] init];
    locationManager.delegate=self;
    locationManager.desiredAccuracy=kCLLocationAccuracyNearestTenMeters;

    [locationManager startUpdatingLocation];
}
- (void) locationManager:(CLLocationManager *) manager didFailWithError:(NSError *)error {

    [locatingAlert dismissWithClickedButtonIndex:0 animated:NO];

    UIAlertView *statusAlert;

    statusAlert =  [[UIAlertView alloc] initWithTitle:@"" message:@"In order to use this application properly, you need to allow use of the GPS." delegate:self cancelButtonTitle:nil otherButtonTitles:nil];
    [statusAlert addButtonWithTitle:@"OK"];
    [statusAlert show];

    //Set Default Coordinates it app not able to get location
    if (mainDelegate.currentLatitude == nil) {
        mainDelegate.currentLatitude = @"28.6317021";
    }

    if (mainDelegate.currentLongitude == nil) {
        mainDelegate.currentLongitude = @"-81.423110";
    }
}
Heena
  • 754
  • 5
  • 18
  • 30

1 Answers1

2

Just find out whats the error

if([[error code] isEqualTo: kCLErrorLocationUnknown])
{
   The location manager was unable to obtain a location value right now.
}

other error codes

kCLErrorLocationUnknown

The location manager was unable to obtain a location value right now.

kCLErrorDenied

Access to the location service was denied by the user.

kCLErrorNetwork

The network was unavailable or a network error occurred.

kCLErrorHeadingFailure

The heading could not be determined.

kCLErrorRegionMonitoringDenied

Access to the region monitoring service was denied by the user.

kCLErrorRegionMonitoringFailure

A registered region cannot be monitored.

kCLErrorRegionMonitoringSetupDelayed

Core Location could not initialize the region monitoring feature immediately.
ipraba
  • 16,485
  • 4
  • 59
  • 58
  • @Heena it won't work on simulator. There are restrictions, biggest one being the hardware. – Praveen S Aug 05 '11 at 06:21
  • find this SO que.. http://stackoverflow.com/questions/1409141/location-manager-error-kclerrordomain-error-0 – ipraba Aug 05 '11 at 06:21