ios – How to get the accurate distance of patients walking in house


If I am using the CoreMotion framework and CMPedometer class to get the distance of the user walking but it’s not the accurate distance of the user walks even when I use the health kit to get the distanceWalkingRunning query then also it’s not got the accurate distance of user walk. how can I get the accurate distance of the user’s walk?

private func startTrackingSteps() {
    
    pedometer.startUpdates(from: Date(), withHandler: { (pedometerData, error) in
        if let pedData = pedometerData{
            print("pedData:\(pedometerData)")
            self.setPedometerData(pedData: pedData)
        } else {
            self.numberOfSteps = nil
        }
    })
}




private func setPedometerData(pedData: CMPedometerData){
        self.numberOfSteps = Int(truncating: pedData.numberOfSteps)
        if let distancee = pedData.distance{
            let averageStepLength = 0.67 // Average step length in meters (adjust as needed)
            let distance = Double(self.numberOfSteps) * averageStepLength
            self.distance = Double(truncating: distancee)
        }
        DispatchQueue.main.async {
            self.stepsLbl.text = "Steps \(self.numberOfSteps)"
            self.distanceLbl.text = "Distance: \(self.getDistanceString(distance: self.distance))"
            self.TimeLbl.text = "Time: \(self.secondsToHoursMinutesSeconds(Date().secondsInBetweenDate(self.startDate)))"
        }
    }

Latest articles

spot_imgspot_img

Related articles

Leave a reply

Please enter your comment!
Please enter your name here

spot_imgspot_img