使用iPhone GPS无需互联网更新用户位置 [英] Updating user location using iPhone GPS without internet
问题描述
现在我已经实现了CoreLocation方法: -
- (void)updatestart
{
//当前位置
_locationManager = [[CLLocationManager alloc]在里面];
_locationManager.desiredAccuracy = kCLLocationAccuracyBest;
_locationManager.delegate = self;
[_locationManager startUpdatingLocation];
$ b - (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
{
NSLog(@didFailWithError:%@,错误);
UIAlertView * errorAlert = [[UIAlertView alloc]
initWithTitle:@错误消息:@无法获取您的位置委托:无cancelButtonTitle:@OKotherButtonTitles:nil];
[errorAlert show]; (CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation {
[_locationManager stopUpdatingLocation];
NSLog(@%f,_ locationManager.location.coordinate.latitude);
NSLog(@%f,_ locationManager.location.coordinate.longitude);
}
我正在获取位置更新,但这只适用于我们有互联网连接。
我猜想使用iPhone GPS即使没有互联网也可以获取位置。
任何有关如何实现这一点
预先感谢。
另一种不需要数据交换的方式是基于手机信号塔的位置,当然你的设备应该有安装了蜂窝芯片。 从你的代码中,我发现应该尽快修复三件事。 获取位置的委托方法已被弃用(取决于您的 I need to get user location and fetch latitude and longitude of even when there is no internet available. Right now i have implemented CoreLocation methods:- and i am getting the location updates but this only works if we have internet connection. I guess using iPhone GPS we can fetch the location even without internet. Any idea of how to implement that?? Thanks in advance. GPS doesn't need data exchange using internet, but it has basically 2 disadvantages: Another way that it doesn't need data exchange is location based on cell tower, but of course your device should have cellular chip installed. From your code I see three things that should be fixed as soon as possible. The delegate methods to get location is deprecated (depending on your
deployment target). Here is a little snippet for the first two
points: 这篇关于使用iPhone GPS无需互联网更新用户位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
$ ol <
)
(这种情况很多在意大利)
的实际位置
有效坐标时停止位置管理器,这意味着:未缓存,水平精度> = 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;
}
}
-(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);
}
-(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;
}
}