我想检查某个位置是否有可用的方位,如果有,请使用它。这基本上就是我正在做的事情:
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/