来了,我有VC一CoreLocation经理,当用户按下“获取路线”按钮,我initalize位置管理和应用程序打开谷歌地图方向与当前位置和一些预定义的目标位置。核心位置,让原来的位置,每当从背景
这是我的问题,如果应用程序不处于后台状态,当前位置几乎总是如此,如果应用程序从同一VC中的背景调用并且用户再次按下“获取方向”按钮,则当前位置通常显示旧位置。总之,我很烦恼多任务和检索位置的时间戳没有解决我的问题。
IBAction为:
if (self.locationManager) {
[_locationManager release];
self.locationManager = nil;
}
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.delegate = self;
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;
self.locationManager.distanceFilter = kCLDistanceFilterNone;
self.locationTimer = [NSTimer scheduledTimerWithTimeInterval:LOCATION_TIMER target:self selector:@selector(stopUpdatingLocationTimer) userInfo:nil repeats:NO];
HUD = [MBProgressHUD showHUDAddedTo:self.navigationController.view animated:YES];
[self.locationManager startUpdatingLocation];
核心位置代表:
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
NSTimeInterval locationAge = -[newLocation.timestamp timeIntervalSinceNow];
NSLog(@"%f",locationAge);
if (locationAge > 3.0)
return;
if (newLocation.horizontalAccuracy < 0)
return;
if (self.currentLocation == nil || self.currentLocation.horizontalAccuracy > newLocation.horizontalAccuracy) {
self.currentLocation = newLocation;
if (self.currentLocation.horizontalAccuracy <= self.locationManager.desiredAccuracy) {
[self stopUpdatingLocations:YES];
}
}
}
马克,我看到它在苹果的LocateMe示例代码,我复制:NSTimeInterval locationAge = - [newLocation.timestamp timeIntervalSinceNow] if(locationAge> 5.0)return;那么,我们说这是错的?他们使用'-timeIntervalSinceNow'所以这将是一个负值,然后通过附加的负极接反 – ubaltaci 2011-12-27 23:16:44
哦,对了。 (这似乎完全屁股向我)你怎么知道你正在得到旧的更新?你确定他们已经超过3秒了吗? – 2011-12-27 23:24:20
我100%肯定,因为,我对赛车进行测试,首先我打开应用程序,并获得方向一些预先定义的场地是正确的,那么我前往appromixately 2-2.5公里,然后我再次启动的应用程序(从后台状态),它给了我错误的位置,这是旧的。我已经测试过3-4次,都是错的。 – ubaltaci 2011-12-27 23:29:06