首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >CoreMotionActivityManager返回汽车或汽车+固定真

CoreMotionActivityManager返回汽车或汽车+固定真
EN

Stack Overflow用户
提问于 2017-08-09 15:22:33
回答 1查看 507关注 0票数 0

我正在尝试检测 ActivtyType,但是问题是,如果“我开车,然后停在车里”,只需检查coreMotion日志:我将继续得到许多混合回调

代码语言:javascript
运行
复制
high Confidence: Automotive: True, Stationary: True 

代码语言:javascript
运行
复制
high confidence: Automotive: True, Stationary: False

代码语言:javascript
运行
复制
low confidence: Automotive: True, Stationary: True

我没有得到唯一的固定:是的,它总是伴随着汽车也是真实的

它们的出现没有多少规律,或者至少我还没有找到一个模式。

问:有没有人找到一种可靠的方法来检测这辆车什么时候是真正的汽车?

我试着计算得到的回调次数,然后做一些计算,但这似乎不可靠。

FWIW当用户下车,然后我得到步行或固定(没有automotive...which是好的)回调,并使用这些回调设置一个标志到true...so之后,如果我得到任何automotive callback...then,我知道这是一个真正的汽车.

我的代码:

代码语言:javascript
运行
复制
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。

EN

回答 1

Stack Overflow用户

发布于 2018-05-23 04:52:04

这就是我的类似用例的工作原理,在这里,我想在.automotive设置时积极地限制交互,但如果交互变得固定,我可以轻松地恢复交互。在记录消息时,它似乎一直保存在.automotive上,直到检测到另一种模式(例如步行)。

由于我与WiFi在繁忙的交通中通勤,我多次看到以下消息:

代码语言:javascript
运行
复制
confidence low, stationary true, automotive true
confidence high, stationary false, automotive true
....

他们一次又一次地切换(我从未见过任何中等信心活动),只有当静止足够的时间(10-12秒)时,才有信心保持平稳、真实、自动的真实状态,所以我不需要那么做。

下面是我要做的代码:

代码语言:javascript
运行
复制
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
        }
    }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45594747

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档