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

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

Domanda

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 ?

È stato utile?

Soluzione

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.

Altri suggerimenti

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top