1
我试图获取iOS中的海拔高度值和磁场值。我一直在搜索这些主题,但我无法找到任何可以正常工作的东西。 a)当我在谈论仰角值时,我想在将我的手机顶部向上移动时以度为单位获得角度。我附上了一张图片,以方便使用。 我一直在尝试这样的,但它不工作:如何获取iOS中的海拔高度和磁场值
.H
#import <CoreMotion/CoreMotion.h>
@property (nonatomic, retain) CMMotionManager *motionManager;
.M
self.motionManager = [[CMMotionManager alloc] init];
[self.motionManager startMagnetometerUpdates];
NSOperationQueue *myQueue = [[NSOperationQueue alloc] init];
[self.motionManager startDeviceMotionUpdatesToQueue:myQueue withHandler:^(CMDeviceMotion *motion, NSError *error){
float degrees = (motion.attitude.roll*180)/M_PI;
NSLog(@"Value of elevation is: %f", degrees);
}];
二)关于磁场,我想要得到的影响设备,磁铁,铁等,影响我的手机的准确性。 *所有值即时得到不正确的这个解决方案(一种的NSTimer的内部):
NSLog(@"magnetometer data -> x: %f", self.motionManager.magnetometerData.magneticField.x);
NSLog(@"magnetometer data -> y: %f", self.motionManager.magnetometerData.magneticField.y);
NSLog(@"magnetometer data -> z: %f", self.motionManager.magnetometerData.magneticField.z);
float magneticField = sqrtf(powf(self.motionManager.magnetometerData.magneticField.x, 2)
+ powf(self.motionManager.magnetometerData.magneticField.y, 2) +
powf(self.motionManager.magnetometerData.magneticField.z, 2));
NSLog(@"magneticField value: %@", magneticField.text);
任何想法如何找出....谢谢
嗨rubrin 感谢您发布您的答案寻找海拔。 我只想知道在哪种格式下我可以找到标高值? – 2017-07-31 05:24:37