android - Can we get the compass direction without a physical compass (e.g. using 2 GPS points ? )
-
07-07-2021 - |
Frage
my phone has no compass, can I get a compass-like direction (angle) without a physical compass (e.g. using 2 GPS points for moving pobject ? ) or any other method ?
Lösung
You can use Location.getBearing to get bearing from location object obtained using LocationManager.
Also you can calculate it manually using Location.bearingTo method.
Android SDK using precise method to operate with locations. The method considers that the earth isn't flat.
Andere Tipps
If the device is moving then capturing multiple GPS locations can be used to get the direction of travel.
Note though that this will only give you the direction of travel, not the orientation of the device.
EDIT: If you have two points direction between those points is simple mathematics, which you can find on any number of websites. I also believe android/iOS etc have some of these functions built in to make things easier.