即使没有可用的互联网,我也需要获取用户位置并获取纬度和经度。
现在我已经实现了 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不需要使用互联网进行数据交换,但它基本上有两个缺点:
由于卫星搜索)
建筑物之间(这在意大利经常发生)
它不需要数据交换的另一种方式是基于蜂窝塔的位置,但当然你的设备应该安装蜂窝芯片。
从您的代码中,我看到应该尽快修复三件事。
实际位置
有效坐标,即:未缓存,水平精度 >=0 且水平精度符合您的要求,
部署目标)。这是前两个的小片段
要点:
-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations{
CLLocation * newLocation = [locations lastObject];
if (newLocation.horizontalAccuracy < 0) {
return;
}
NSTimeInterval interval = [newLocation.timestamp timeIntervalSinceNow];
if (abs(interval)>20) {
return;
}
}
关于iphone - 在没有互联网的情况下使用 iPhone GPS 更新用户位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17269921/