我想讓我的應用程序獲取他每秒鐘的位置(經度和緯度),這有可能嗎?我有這樣的代碼,到目前爲止,每3秒獲得應用程序的當前位置,但如果我移動它不更新......如何從位置管理器獲取當前位置?
- (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];
}
/*
NSLog「陰莖」真的很優雅。有沒有人閱讀文檔了? – Nick 2010-07-23 06:44:56