android - Can we get the compass direction without a physical compass (e.g. using 2 GPS points ? )

StackOverflow https://stackoverflow.com/questions/12910941

Question

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 ?

Était-ce utile?

La solution

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.

Autres conseils

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.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top