【问题标题】:CoreMotion frameworkCoreMotion 框架
【发布时间】:2011-03-16 02:09:04
【问题描述】:

我最近在做一个指南针,涉及到CoreMotion框架,但是查了半天没找到关于如何实现这个框架的指南针效果的资料,希望能得到大家的帮助。

【问题讨论】:

    标签: compass-geolocation


    【解决方案1】:

    【讨论】:

      【解决方案2】:

      我的“Helloworld”CoreMotion:

      1) 添加CoreMotion.framework

      2) 在.h 文件中:

      #import <CoreMotion/CoreMotion.h>
      

      3) 在 .m 文件中:

      CMMotionManager *myMotionManager= [[CMMotionManager alloc] init];
      myMotionManager.deviceMotionUpdateInterval = 1/60;
      [myMotionManager startDeviceMotionUpdatesUsingReferenceFrame:CMAttitudeReferenceFrameXMagneticNorthZVertical  toQueue:[NSOperationQueue currentQueue] withHandler:^(CMDeviceMotion *motion, NSError *error) {
           double x = myMotionManager.deviceMotion.magneticField.field.x;
           double y = myMotionManager.deviceMotion.magneticField.field.y;
           double z = myMotionManager.deviceMotion.magneticField.field.z;
          NSLog(@"Strength of Earth's magnetic field= %8.2f",sqrt(x*x+y*y+z*z));
          myLabel.text = [NSString stringWithFormat:@"%8.2f", sqrt(x*x+y*y+z*z)];
      }];
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-12-16
        • 2014-02-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-07-29
        相关资源
        最近更新 更多