2016-04-04 12 views
0

は、私のコードは、単にこれです:IOS-didFailWithError:エラードメイン= kCLErrorDomainコード= 0。 (kCLErrorDomainエラー0)」私は、ユーザーの現在位置の経度&緯度を取得しようと

didFailWithError: Error Domain=kCLErrorDomain Code=0 "The operation couldn’t be completed. (kCLErrorDomain error 0.)" 
:私は常にdidFailWithError方法から、このエラーを得た

- (void)viewDidLoad { 
    self.locationManager=[[CLLocationManager alloc]init]; 
    [locationManager setDelegate:self]; 
    [locationManager setDesiredAccuracy:kCLLocationAccuracyNearestTenMeters]; 
    [locationManager startUpdatingLocation]; 
} 

-(void)locationManager:(CLLocationManager *)manager 
didUpdateToLocation:(CLLocation *)newLocation 
fromLocation:(CLLocation *)oldLocation 
{ 
    float latitude=newLocation.coordinate.latitude; 
    float longitude=newLocation.coordinate.longitude; 
    NSLog(@"%f",latitude); 
    NSLog(@"%f",longitude); 
    [locationManager stopUpdatingLocation]; 

} 
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error 
{ 
    NSLog(@"didFailWithError: %@", error); 
} 

enter image description here

+0

私は、ネットワークをリセットするが、まだいけない仕事。 @derpoliuk –

+0

@ Mr.Bondデバッグ>場所>現在地 –

+0

でも動作していないことを確認してください@ bhavin ramani –

答えて

1

私はあなたのプロジェクト

01に .plistで、次の権限を追加する必要が 、だと思います

し、その値がApplication would like to use your location

であり、第二は、あなたのコード内で[locationManager requestWhenInUseAuthorization];行を追加し、です。

this code in i added :

- (void)viewDidLoad { 
    self.locationManager=[[CLLocationManager alloc]init]; 
    [locationManager setDelegate:self]; 
    [locationManager setDesiredAccuracy:kCLLocationAccuracyNearestTenMeters]; 
    [locationManager requestWhenInUseAuthorization]; 
    [locationManager startUpdatingLocation]; 

} 
関連する問題