指南针校准目标c [英] Compass calibration objective-c

查看:192
本文介绍了指南针校准目标c的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在ios应用程序中尝试使用指南针。我有一个问题。如果我实现
locationManagerShouldDisplayHeadingCalibration 方法和返回YES ,则校准显示始终显示。但我应该像苹果地图一样。即有时会显示校准显示。当指南针应该被校准时。

解决方案

OK我不能发表评论,所以我认为我应该留下一个回复,因为Shadow_x99的回复是对我有用。



我正在使用这个改进版的Shadow_x99的回复< a>。

   - (BOOL)locationManagerShouldDisplayHeadingCalibration:(CLLocationManager *)manager {
if(!manager.heading)返回YES;没有什么,我们可以假设我们要校准。
else if(manager.heading.headingAccuracy< 0)return YES; // 0表示无效标题,需要校准
else if(manager.heading.headingAccuracy> 5)返回YES; // 5度是一个小的值,对我的需求也是正确的。
else return NO; // 一切都很好。指南针足够精确。
}

还想说什么Shadow_x99几乎实现了API文档 here 其中指出:


如果您从此方法返回NO,或不提供其实现在您的代表中,Core Location不显示标题校准警报。即使没有显示警报,当任何干扰磁场远离设备时,校准仍然可以自然发生。 但是,如果设备由于任何原因无法自行校准,任何后续事件的标准属性属性中的值将反映未校准的读数。



I try use compass in my ios app. And I have one problem with it. If i implement locationManagerShouldDisplayHeadingCalibration method and return YES in it, then calibration display is showing always. But I should make it like apple maps. I.e. calibration display should be showed sometimes. When compass should be calibration.

解决方案

OK I could not leave a comment so I thought I should leave a reply as Shadow_x99's reply was useful to me.

I am using this improved version of Shadow_x99's response.

- (BOOL)locationManagerShouldDisplayHeadingCalibration:(CLLocationManager *)manager{
      if(!manager.heading) return YES; // Got nothing, We can assume we got to calibrate.
      else if(manager.heading.headingAccuracy < 0 ) return YES; // 0 means invalid heading, need to calibrate
      else if(manager.heading.headingAccuracy > 5 ) return YES; // 5 degrees is a small value correct for my needs, too.
      else return NO; // All is good. Compass is precise enough.
}

Also wanted to say what Shadow_x99 says almost implements the API docs here which states:

If you return NO from this method or do not provide an implementation for it in your delegate, Core Location does not display the heading calibration alert. Even if the alert is not displayed, calibration can still occur naturally when any interfering magnetic fields move away from the device. However, if the device is unable to calibrate itself for any reason, the value in the headingAccuracy property of any subsequent events will reflect the uncalibrated readings.

这篇关于指南针校准目标c的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆