'Official android.location.Location.getBearing() documentation out of sync with Android project source code
The source code for getBearing() method states:
/**
* Get the bearing, in degrees.
*
* <p>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.
*
* <p>If this location does not have a bearing then 0.0 is returned.
*/
But the official Android docs for that class have the range defined as:
The bearing is guaranteed to be in the range [0, 360).
which clearly differs in whether 0 or 360 is valid or invalid, i.e. the invalid bearing of 0.0 which indicates the Location does not have a bearing, is valid according to the developer portal docs.
The weird thing the source for this class has basically stayed the same for years and the documentation for it in developer portal has changed only recently to this.
If there is a place where I could report this issue to the maintainers of the developer portal, please let me know.
Solution 1:[1]
The documentation is generated from the source code. So I would expect the code to be correct, and the documentation just to need to be re uploaded. The difference between these two can be solved by using getBearing()%360.0f, which will force it into [0,360.0)
Solution 2:[2]
If you think about it: 360 degrees are a full turn. So 0° is equal to 360° degrees after normalization. the desync is propably because of a different version, cause the official doku is also javadoc.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Gabe Sechan |
| Solution 2 | saltycoder815 |
