데이터가 없어도 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];
}
그래서 휴대 전화 또는 Wi-Fi 데이터를 필요로하지 않고 위도 및 경도 좌표를 얻을 수있는 방법이있다라고? – user717452
표준 위치 서비스는 네트워크/데이터 연결없이 작동해야합니다. 위치 서비스를 사용 중지하는 비행기 모드를 사용 설정하면이 기능을 테스트 할 수 있습니다. 역 지오 코드 요청을하고 값을보기 전에 중단 점을 삽입하여이를 테스트 할 수 있습니다. –
현재 위치를 얻기 위해'CLLocationManager'를 사용하는 현재 코드는 인터넷 연결 없이도 작동합니다. 그러나 reverseGeocodeLocation에 대한 호출은 네트워크에 연결되어 있지 않으면 작동하지 않습니다. –