我已经设法使用CLLocationManager获得罗盘航向,但因为我的应用程序已经使用CMMotionManager,所以我想只使用CMMotionManager测量航向。
像所有的Apple模糊文档一样,你必须猜测如何使用他们的API。
我试着用它来测量航向。
[self.motionManager setMagnetometerUpdateInterval:1.0/30.0]; //30 Hz
[self.motionManager startMagnetometerUpdatesToQueue:[NSOperationQueue currentQueue] withHandler:^(CMMagnetometerData *magnetometerData, NSError *error) {
CMMagneticField compass = magnetometerData.magneticField;
NSLog(@"x: %f y:%f z:%f", compass.x, compass.y, compass.z);
}];问题是这个块只运行了几秒钟,然后就停止运行了。
有没有专门使用CMMotionManager测量航向的例子?
谢谢。
发布于 2013-04-05 11:25:36
显然,最好的方法是使用CoreLocation,直到苹果创建出像样的文档。
发布于 2013-04-05 03:12:25
在没有实际尝试的情况下,我建议使用[NSOperationQueue mainQueue]而不是currentQueue。通常,您只能从操作内部调用currentQueue来获取对启动该操作的队列的引用。
发布于 2013-04-05 03:17:38
我建议你不要给start...UpdatesToQueue:withHandler:打电话。这需要使用后台线程,并且管理起来非常棘手。你可能只是把主线上的一切都搞乱了。这是一种先进的技术,你不需要它。
相反,只需使用start,然后使用NSTimer或类似的命令来重复轮询CMMotionManager。
https://stackoverflow.com/questions/15818527
复制相似问题