Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/108.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 罗盘校准物镜-c_Iphone_Ios_Objective C_Map - Fatal编程技术网

Iphone 罗盘校准物镜-c

Iphone 罗盘校准物镜-c,iphone,ios,objective-c,map,Iphone,Ios,Objective C,Map,我尝试在ios应用程序中使用compass。我有一个问题。如果我实施 LocationManager应显示HeadingCalibration方法,并在其中返回YES,然后校准显示始终显示。但我应该让它像苹果地图一样。即,有时应显示校准显示。校准指南针的时间。我使用以下代码: @property (nonatomic, retain) CLHeading * currentHeading; // Value updated by @selector(locationManager:didUpda

我尝试在ios应用程序中使用compass。我有一个问题。如果我实施
LocationManager应显示HeadingCalibration
方法,并在其中
返回YES
,然后校准显示始终显示。但我应该让它像苹果地图一样。即,有时应显示校准显示。校准指南针的时间。

我使用以下代码:

@property (nonatomic, retain) CLHeading * currentHeading; // Value updated by @selector(locationManager:didUpdateHeading:)
...
...
- (BOOL)locationManagerShouldDisplayHeadingCalibration:(CLLocationManager *)manager{
      if( !self.currentHeading ) return YES; // Got nothing, We can assume we got to calibrate.
      else if( self.currentHeading.headingAccuracy < 0 ) return YES; // 0 means invalid heading. we probably need to calibrate
      else if( self.currentHeading.headingAccuracy > 5 )return YES; // 5 degrees is a small value correct for my needs. Tweak yours according to your needs.
      else return NO; // All is good. Compass is precise enough.
}
@属性(非原子,保留)CLHeading*currentHeading;//由@selector更新的值(locationManager:didUpdateHeading:)
...
...
-(布尔)位置管理器应显示标题校准:(CLLocationManager*)管理器{
如果(!self.currentHeading)返回YES;//什么都没有,我们可以假设我们必须进行校准。
否则如果(self.currentHeading.headingAccuracy<0)返回YES;//0表示无效的标题。我们可能需要校准
否则,如果(self.currentHeading.headingAccuracy>5)返回YES;//5度是一个很小的值,适合我的需要。根据需要调整你的值。
否则返回否;//一切正常。罗盘足够精确。
}

好的,我不能留下评论,所以我想我应该留下回复,因为克劳德·霍勒的回复对我很有用

我用的是克劳德·霍勒的改进版

-(BOOL)位置管理器应显示HeadingCalibration:(CLLocationManager*)管理器{
如果(!manager.heading)返回YES;//什么都没有,我们可以假设我们必须进行校准。
否则如果(manager.heading.headingAccuracy<0)返回YES;//0表示无效的标题,需要校准
否则,如果(manager.heading.headingAccuracy>5)返回YES;//5度也是一个很小的值,适合我的需要。
否则返回否;//一切正常。罗盘足够精确。
}
还想说明Claude Houle所说的几乎实现了API文档,其中说明:

如果此方法返回“否”,或未在代理中为其提供实施,则Core Location不会显示标题校准警报。即使未显示警报,当任何干扰磁场从设备移开时,校准仍会自然发生但是,如果设备由于任何原因无法校准自身,任何后续事件的headingAccuracy属性中的值将反映未校准的读数。


标题是CLHeading。这就是为什么manager.heading>5将发出警告。self.currentHeading.headingAccuracy>5是正确的

更直接的解决方案:

目标-C

- (BOOL)locationManagerShouldDisplayHeadingCalibration:(CLLocationManager *)manager
{
    CLLocationDirection accuracy = [[manager heading] headingAccuracy];
    return accuracy <= 0.0f || accuracy > 10.0f;
}
-(BOOL)位置管理器应显示HeadingCalibration:(CLLocationManager*)管理器
{
CLLocationDirection准确性=[[管理者标题]标题准确性];
返回精度10.0f;
}
这利用了在nil对象上执行的选择器总是返回零的事实,以及精度永远不会有效且等于0.0f(即100%精度)的事实

Swift

由于引入了optionals,最简单的Swift解决方案确实需要分支,看起来像:

func locationManagerShouldDisplayHeadingCalibration(manager: CLLocationManager) -> Bool {
    if let h = manager.heading {
        return h.headingAccuracy < 0 || h.headingAccuracy > 10
    }
    return true
}
函数位置管理器应显示标题校准(管理器:CLLocationManager)->Bool{
如果设h=manager.heading{
返回h.headingAccuracy<0 | | h.headingAccuracy>10
}
返回真值
}
请注意,我们关注的是
标题准确性
,苹果公司的文档中指出:

此属性中的正值表示潜在错误 在MagnetizeReading属性报告的值和 磁北的实际方向。因此,该值越低 属性,则标题越精确。负值意味着 所报告的标题无效,当设备运行时可能会发生这种情况 未校准或存在来自局部磁场的强干扰 田地


在我的iPhone6上,headingAccuracy通常为25.0,因此返回YES并依靠iOS来确定何时显示校准屏幕似乎是最好的选择。
丢弃标题准确度<0.0的读数可防止使用“错误”标题。

我不认为这是真的,我喜欢强制始终显示校准,但只有在设备认为需要时才会显示校准。哪款ios?v6+,我使用的是OSM地图我的经验是,如果你在户外,有一个机械罗盘,那么我发现你每次使用iphone时都必须校准它。所以我想强制校准视图出现,即使ios认为它不是必需的。但这不起作用,您不能强制它显示calib窗口。尝试:校准它,然后离开视图,再次输入,您是否再次看到校准视图?我有一个相反的问题:校准对话框(与您的完全相同)从未显示,即使在完全相同的位置(即坐在我的办公桌旁),“Compass”应用程序不断显示对话框。谢谢。只是检查了我的代码,是的,有那个错误,更新了答案。您的响应更简洁(知道null为0)。对于当时像我这样的初学者,可以帮助解释一下这些检查。当调用
LocationManager shouldDisplayHeadingCalibration
时,您是否见过
headingAccuracy
低于5?我猜你的答案是否定的,因为5度太接近iOS能保证的精度(至少在某些设备上)。“我认为我的观点是正确的。”我相信这是一个答案,也是一个正确的答案。
func locationManagerShouldDisplayHeadingCalibration(manager: CLLocationManager) -> Bool {
    if let h = manager.heading {
        return h.headingAccuracy < 0 || h.headingAccuracy > 10
    }
    return true
}