Want to capture iOS device posture at an angle

Asked 1 years ago, Updated 1 years ago, 76 views

I want to get the posture of the iOS device from the gyro, but I don't know how to do it.

I looked it up and found out that
http://qiita.com/yimajo/items/49bd534e8c257294a2e3
This article is closest to what I'm looking for, but I can't refer to it because it's old...

https://developer.apple.com/reference/coremotion/cmattitude
I also looked at the API reference, but I don't know how to get roll, pitch, and yaw!

I would appreciate it if you could give me some advice.

Also, I have another question. I think the position of the iOS device is GPS and the posture can be obtained from the gyro, but is it not possible to obtain the height where the device exists?
I would appreciate it if you could reply to me together.

swift ios

2022-09-30 21:23

1 Answers

It's a bit rough to say that it's not helpful because it's old information.I would like you to realize that it is the questioner himself who will be disadvantaged by narrowing down the source of information obtained in this way.The CoreMotion framework description of the linked information is not old at all, and I think it's helpful.

First of all, I will list the sample code of Objective-C, which is linked to Swift3.Copy and paste to allow real installation.

import UIKit
import CoreMotion

classViewController:UIViewController {

    @IBOutlet weak var pitchLabel:UILabel!
    @IBOutlet weak var rollLabel:UILabel!
    @IBOutlet weak variableawLabel: UILabel!

    variationManager:CMMotionManager?

    override func viewDidLoad(){
        super.viewDidLoad()

        motionManager=CMMotionManager()
        motionManager?.deviceMotionUpdateInterval=1.0
    }

    @ IBAction func getAttitude(_sender:Any){
        attribute()
    }

    funcattitude(){
        guardlet_=motionManager?isDeviceMotionAvailable,
        let operationQueue = OperationQueue.current
        else{
            return
        }

        motionManager?startDeviceMotionUpdates(to:operationQueue, withHandler:{motion,_in)
            iflet attribute=motion?.attitude{
                self.pitchLabel.text=String (format: "%0.2f", attribute.pitch*180.0/Double.pi)
                self.rollLabel.text=String (format: "%0.2f", attribute.roll*180.0/Double.pi)
                self.yawLabel.text=String (format: "%0.2f", attribute.yaw*180.0/Double.pi)
            }
        })
    }

}

*Wouldn't it be very difficult to transplant if we could increase our experience in programming with Swift rather than our knowledge and experience with Objective-C?

Is it not possible to obtain the height where the device exists?

You should be able to get it by GPS.I'm not familiar with it either, so I'll refrain from explaining further, but wouldn't I be able to find information in Japanese if I didn't like the source?


2022-09-30 21:23

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.