2016-09-20 2 views
0

데이터가 없어도 iOS 앱에서 GPS 좌표를 가져올 수 있어야합니다. 나는 이것이 문제가 될 것이라고 생각하지 않았다. GPS는 셀룰러 신호와 별개이지만, 이것에 문제가있다. 여기까지 내가 지금까지 가지고있는 것이있다. 셀룰러 데이터가 꺼져있는 경우에, 나는 오류 메시지를 얻을하지 않습니다, 그냥 좌표를 취득에 실패하고 그 값이 널 (null) 잎 :iOS 셀룰러 데이터가없는 경우 GPS 좌표 받기

- (void)viewDidLoad { 
    [super viewDidLoad]; 
    self.locationManager = [[CLLocationManager alloc] init]; 
    self.locationManager.delegate = self; 
    self.locationManager.desiredAccuracy=kCLLocationAccuracyBest; 
    self.locationManager.distanceFilter=kCLDistanceFilterNone; 
    [self.locationManager requestWhenInUseAuthorization]; 
    [self.locationManager startUpdatingLocation]; 
    geocoder = [[CLGeocoder alloc] init]; 
} 
-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations { 
    CLLocation *newLocation = [locations lastObject]; 
    [geocoder reverseGeocodeLocation:newLocation completionHandler:^(NSArray *placemarks, NSError *error) { 
     if (error == nil&& [placemarks count] >0) { 
      placemark = [placemarks lastObject]; 
      NSString *latitude, *longitude, *state, *country; 
      latitude = [NSString stringWithFormat:@"%f",newLocation.coordinate.latitude]; 
      longitude = [NSString stringWithFormat:@"%f",newLocation.coordinate.longitude]; 
      self.theCoord.text = [[latitude stringByAppendingString:@", "] stringByAppendingString:longitude]; 

     } else { 
      NSLog(@"%@", error.debugDescription); 
     } 
    }]; 
    // Turn off the location manager to save power. 
    [self.locationManager stopUpdatingLocation]; 
} 

답변

3

위치 업데이트없이 인터넷으로 작동해야하지만 지오 코딩은하지 않습니다. 그것은 네트워크 서비스입니다. 내 생각 엔 당신이 위치 업데이 트를 받고 있지만 reverseGeocodeLocation에 대한 호출이 실패했습니다. 중단 점을 설정하고 코드를 추적하여 어떤 일이 일어나는지 확인해야합니다.

+0

그래서 휴대 전화 또는 Wi-Fi 데이터를 필요로하지 않고 위도 및 경도 좌표를 얻을 수있는 방법이있다라고? – user717452

+0

표준 위치 서비스는 네트워크/데이터 연결없이 작동해야합니다. 위치 서비스를 사용 중지하는 비행기 모드를 사용 설정하면이 기능을 테스트 할 수 있습니다. 역 지오 코드 요청을하고 값을보기 전에 중단 점을 삽입하여이를 테스트 할 수 있습니다. –

+1

현재 위치를 얻기 위해'CLLocationManager'를 사용하는 현재 코드는 인터넷 연결 없이도 작동합니다. 그러나 reverseGeocodeLocation에 대한 호출은 네트워크에 연결되어 있지 않으면 작동하지 않습니다. –

0

애플 문서는 https://developer.apple.com/reference/corelocation/clgeocoder

A geocoder object is a single-shot object that works with a network-based service to look up placemark information for its specified coordinate value.

+0

좋은 지적이지만, OP 질문에 대한 답변이 아닙니다. –