                     DispatchQueue.global(qos:DispatchQoS.QoSClass.background).async
                     { [weak self] in
                         
+                        let acceleration:CMAcceleration = dataMotion.gravity
+                        let attitude:CMAttitude = dataMotion.attitude
+                        let rotation:CMRotationMatrix = attitude.rotationMatrix
                         self?.gravityCompute(acceleration:acceleration)
+                        
+//                        print((attitude.yaw + (Double.pi / 2)) * -180.0 / Double.pi)
+                        
+                        let heading = Double.pi + atan2(rotation.m22, rotation.m12)
+                        let headingDegrees = heading * 180.0 / Double.pi
+                        
+                        print(headingDegrees)
                     }
                 }
             }

        
        if manager.isDeviceMotionAvailable
        {
            manager.deviceMotionUpdateInterval = kUpdatesInterval
            manager.startDeviceMotionUpdates(
                to:OperationQueue.main)
            { (data:CMDeviceMotion?, error:Error?) in
                

                {
                    guard
                        
                        let dataMotion:CMDeviceMotion = data
                        
                    else
                    {
