我正在尝试检测 ActivtyType,但是问题是,如果“我开车,然后停在车里”,只需检查coreMotion日志:我将继续得到许多混合回调
high Confidence: Automotive: True, Stationary: True 或
high confidence: Automotive: True, Stationary: False或
low confidence: Automotive: True, Stationary: True我没有得到唯一的固定:是的,它总是伴随着汽车也是真实的
它们的出现没有多少规律,或者至少我还没有找到一个模式。
问:有没有人找到一种可靠的方法来检测这辆车什么时候是真正的汽车?
我试着计算得到的回调次数,然后做一些计算,但这似乎不可靠。
FWIW当用户下车,然后我得到步行或固定(没有automotive...which是好的)回调,并使用这些回调设置一个标志到true...so之后,如果我得到任何automotive callback...then,我知道这是一个真正的汽车.
我的代码:
func beginMotionTracking(){
let motionLog = OSLog(subsystem: "Spike", category: "Motion")
shouldUseTimer = false
motionActivityManager = CMMotionActivityManager()
var totalWalking = 0
var totalAutomotive = 0
var totalStationary = 0
var totalFalseAutomotive = 0
motionActivityManager?.startActivityUpdates(to: OperationQueue.main){
[weak self] activity in
os_log("Motion is Tracking | desiredAccuracy is %{public}f | RemainingTime : %{public}f ",log: motionLog, type: .default, (self?.locationManager.desiredAccuracy)! , UIApplication.shared.remainingTime())
if activity?.walking == true && (activity?.confidence == .medium || activity?.confidence == .high) && activity?.automotive == false && activity?.stationary == false && activity?.unknown == false {
totalWalking += 1
os_log("medium and high conf: walking %{public}d time", log: motionLog, type: .error, totalWalking)
}else if activity?.stationary == true && (activity?.confidence == .medium || activity?.confidence == .high) && activity?.automotive == false && activity?.walking == false && activity?.unknown == false {
totalStationary += 1
os_log("medium and high conf: stationary %{public}d time", log: motionLog, type: .error, totalStationary)
// false automotive
}else if activity?.automotive == true && activity?.stationary == true && (activity?.confidence == .high) && activity?.walking == false && activity?.unknown == false {
totalFalseAutomotive += 1
os_log("high conf: FALSE Automotive %{public}d time", log: motionLog, type: .error, totalFalseAutomotive)
if totalFalseAutomotive > 2{
totalFalseAutomotive = 0
totalAutomotive = 0
totalStationary = 0
totalWalking = 0
os_log("Too many FALSE automotives, REST all counts back to 0", log: motionLog, type: .fault)
}
}
else if activity?.automotive == true && (activity?.confidence == .high) && activity?.walking == false && activity?.stationary == false && activity?.unknown == false {
totalAutomotive += 1
os_log("high conf: Automotive %{public}d time", log: motionLog, type: .error, totalAutomotive)
if ((totalWalking > 3 && totalAutomotive > 2) || (totalStationary > 3 && totalAutomotive > 2) || (totalAutomotive > 7)){
self?.locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters
os_log("Motion is Automotive and is about to be stopped: desired AccuracyChanged to HundredMeters | RemainingTime : %{public}f ", log: motionLog, type: .fault, UIApplication.shared.remainingTime())
self?.shouldUseTimer = true
self?.motionActivityManager?.stopActivityUpdates()
}
}
}
}我正在经历所有这些麻烦,因为我试图降低我的core-location的准确性,每当用户驾驶不超过3分钟,然后使用核心运动来检测automotive运动,并使用它来使定位精度回到hundredMeter。
发布于 2018-05-23 04:52:04
这就是我的类似用例的工作原理,在这里,我想在.automotive设置时积极地限制交互,但如果交互变得固定,我可以轻松地恢复交互。在记录消息时,它似乎一直保存在.automotive上,直到检测到另一种模式(例如步行)。
由于我与WiFi在繁忙的交通中通勤,我多次看到以下消息:
confidence low, stationary true, automotive true
confidence high, stationary false, automotive true
....他们一次又一次地切换(我从未见过任何中等信心活动),只有当静止足够的时间(10-12秒)时,才有信心保持平稳、真实、自动的真实状态,所以我不需要那么做。
下面是我要做的代码:
func handleMotionActivityUpdates(activity: CMMotionActivity?) {
if let a = activity {
if a.automotive && !a.stationary && (a.confidence == .medium || a.confidence == .high) {
//restrict interaction
} else
if (!a.automotive || a.stationary) && (a.confidence == .medium || a.confidence == .high) {
//re-enable interaction
}
}
}https://stackoverflow.com/questions/45594747
复制相似问题