2011-08-05 76 views
0

我使用CLLocationManager搶location.Though I have GPS settings working on my device CLLocation deletgate方法,它顯示隨機狀態彈出這是在didFailWithErroriphone:所謂隨機

錯誤我收到定義是,

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"; 
    } 
} 
+0

請看看這個http://mobileorchard.com/hello-there-a-corelocation-tutorial/ –

+0

你是怎麼調用這個委託的? –

+0

沒有它本身稱爲 – Heena

回答

2

只要找到了什麼錯誤

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

其他錯誤代碼

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. 
+1

是用於模擬器我得到kCLErrorDomain錯誤 – Heena

+0

@Heena它不會在模擬器工作。有限制,最大的是硬件。 –

+0

發現這個SO闕.. http://stackoverflow.com/questions/1409141/location-manager-error-kclerrordomain-error-0 – iPrabu