即使没有可用的互联网,我也需要获取用户位置并获取纬度和经度。
现在我已经实现了 CoreLocation 方法:-
-(void)updatestart
{
// Current location
_locationManager = [[CLLocationManager alloc]init];
_locationManager.desiredAccuracy = kCLLocationAccuracyBest;
_locationManager.delegate = self;
[_locationManager startUpdatingLocation];
}
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
{
NSLog(@"didFailWithError: %@", error);
UIAlertView *errorAlert = [[UIAlertView alloc]
initWithTitle:@"Error" message:@"Failed to Get Your Location" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[errorAlert show];
}
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation{
[_locationManager stopUpdatingLocation];
NSLog(@"%f",_locationManager.location.coordinate.latitude);
NSLog(@"%f",_locationManager.location.coordinate.longitude);
}
我正在获取位置更新,但这仅在我们有互联网连接的情况下才有效。
我想即使没有互联网,我们也可以使用 iPhone GPS 获取位置。
知道如何实现吗?
提前致谢。