【发布时间】:2013-06-24 07:16:18
【问题描述】:
即使没有可用的互联网,我也需要获取用户位置并获取纬度和经度。
现在我已经实现了 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 即使没有互联网,我们也可以获取位置。
知道如何实现吗?
提前致谢。
【问题讨论】:
-
如果你在晴朗的天空下,你可能会得到位置,因为你的 GPS 接收器直接访问 GPS,你不需要任何互联网。但是,如果您在任何屋檐下,那么 GPS 接收器无法直接访问 GPS,那么它会使用您的互联网来定位您。
-
你的意思是说通过使用上述相同的方法我可以使用 GPS 更新用户位置??
标签: iphone ios objective-c geolocation