我正在寻找一个开源应用程序或库来跟踪后台的用户位置.现在我正在尝试使用CLLocation
和后台任务,但准确性对我的情况来说还不够.你能解释一下,像"移动","管理员","endmondo"等应用程序如何创建我的路线?我应该使用Accelerometer或/和指南针在CLLocation背景点之间创建路线吗?
一些代码:
//location manager init
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.distanceFilter = kCLDistanceFilterNone;
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;
self.locationManager.delegate = self;
#pragma mark - CLLocationManager Delegate
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
if ([self isInBackground]) {
if (self.locationUpdatedInBackground) {
bgTask = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler: ^{
[[UIApplication sharedApplication] endBackgroundTask:bgTask];
}];
self.locationUpdatedInBackground(newLocation);
[self endBackgroundTask];
}
} else {
if (self.locationUpdatedInForeground) {
self.locationUpdatedInForeground(newLocation);
}
}
}
Run Code Online (Sandbox Code Playgroud)
UPD:Justed使用下一个属性测试了我的应用程序
self.locationManager.distanceFilter = kCLDistanceFilterNone;
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;
self.locationManager.activityType = CLActivityTypeFitness;
self.locationManager.pausesLocationUpdatesAutomatically=NO;
Run Code Online (Sandbox Code Playgroud)
在这种情况下,我在1.5小时旅行期间有大约10个被解雇的事件