Iphone 如何从位置管理器获取当前位置?
我希望我的应用程序每秒都能得到他所在位置的准确经纬度,有可能吗?到目前为止,我有这个代码,每3秒钟应用程序就会得到当前位置,但如果我移动,它不会更新Iphone 如何从位置管理器获取当前位置?,iphone,localization,location,Iphone,Localization,Location,我希望我的应用程序每秒都能得到他所在位置的准确经纬度,有可能吗?到目前为止,我有这个代码,每3秒钟应用程序就会得到当前位置,但如果我移动,它不会更新 - (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation{ NSLog(@"lol"); [locationMa
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation{
NSLog(@"lol");
[locationManager stopUpdatingLocation];
if (wtf == 2) {
[[NSUserDefaults standardUserDefaults] setObject:newLocation forKey:@"old"];
NSLog(@"wtf");
wtf =0;
}
oldLocation = [[NSUserDefaults standardUserDefaults] objectForKey:@"old"];
double rep = [oldLocation distanceFromLocation:newLocation];
NSString *label1 = [NSString stringWithFormat:@"%2.90f",oldLocation.coordinate.latitude];
NSString *label2 = [NSString stringWithFormat:@"%2.90f",newLocation.coordinate.latitude];
if ([label1 isEqual:label2]) {
NSLog(@"penis");
}
labelm.text = label1;
labelkm.text = label2;
}
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error {
}
-(void)actualise{
[locationManager startUpdatingLocation];
}
- (void)viewDidLoad {
[super viewDidLoad];
wtf = 2;
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[locationManager startUpdatingLocation];
[NSTimer scheduledTimerWithTimeInterval:3 target:self selector:@selector(actualise) userInfo:nil repeats:YES];
}
/*
使用以下代码初始化并启动位置管理器:
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.distanceFilter = kCLDistanceFilterNone;
locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters;
[locationManager startUpdatingLocation];
并按如下方式实现DidUpdateLocation:
- (void) locationManager:(CLLocationManager*)manager didUpdateToLocation:(CLLocation*)newLocation fromLocation:(CLLocation*) oldLocation
{
// This will be called every time the device has any new location information.
}
不需要使用任何计时器。NSLog阴茎真的很经典。还有人阅读文档吗?好的,但我需要每秒知道确切的位置,因此如果我每秒在街上跑步,它将更改位置?将distanceFilter和desiredAccuracy设置为最低将为您提供最多的更新。但是没有理由说你每秒钟都会得到更新。只有当GPS装置检测到它已移动时,您才会得到更新。