android - Android Location hasBearing 检查什么?

标签 android location

我想检查某个位置是否有可用的方位,如果有,请使用它。这基本上就是我正在做的事情:

if (loc.hasBearing()) {
    // code that uses bearing
} else {
    // log no bearing
}

if block 中的代码在许多方位角为 0 (Math.floor'd) 的位置上执行,而 0 并不是实际的方位角。

我确实尝试确保我获得轴承(或者至少我使用支持轴承的提供商):

criteria.setBearingRequired(true);
criteria.setBearingAccuracy(Criteria.ACCURACY_MEDIUM); 

我正在将位置放入 Intent 的附加项中,然后再次将其取出......也许这与它有关?我只是使用 putExtra 和 getParcelable - 我不认为这会破坏位置。

我正在考虑忽略 0.0 的方位,这应该不会有太多误报,但我希望能够更干净地使用 API。

最佳答案

来自 documentation :

Get the bearing, in degrees.

Bearing is the horizontal direction of travel of this device, and is not related to the device orientation. It is guaranteed to be in the range (0.0, 360.0] if the device has a bearing.

If this location does not have a bearing then 0.0 is returned.

由于如果该位置没有方位,getBearing() 返回 0.0,因此您可以安全地忽略它。

关于android - Android Location hasBearing 检查什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44574738/

相关文章:

jquery - 如何使用 jQuery 的 $.post 函数获取 "location" header ?

android - 如果实现 GooglePlayServicesClient.ConnectionCallbacks/OnConnectionFailedListener,则找不到主 Activity 类

android - Android P错误:无法解决依赖关系问题

Android点击时更改背景颜色

Android 在测试期间信任自签名证书

java - 如何修复 InstallException/ShellCommandUnresponsiveException?

android - 将艺术品附加到 ExoPlayer 的 mp3 Uri

iphone - Xcode 4.2 编译错误

android - 如何在Kotlin中设置从服务到 Activity 的回调?

javascript - window.location.replace() 无法重定向浏览器