1

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 ?

MSaudi
  • 4,442
  • 2
  • 40
  • 65
  • Here is an example for what you're asking for. http://stackoverflow.com/questions/8734190/android-compass-example – Yicanis Oct 16 '12 at 09:00

2 Answers2

2

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.

Gregory Kalabin
  • 1,760
  • 1
  • 19
  • 45
  • Can I depend on this in matter of accuracy? I mean can I ignore the compass completely ? I only need the direction in travelling mode. – MSaudi Oct 16 '12 at 15:11
  • 1
    @drdigital If you have to know direction of travel - use this. Compass provides orientation of the device. The difference is when you are going backwards: device has an azimuth opposite to the direction of travel. – Gregory Kalabin Oct 16 '12 at 17:59
1

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.

Jon Taylor
  • 7,865
  • 5
  • 30
  • 55
  • If the points are formatted as such - (X, Y) (X, Y) then the simple math would be the square root of (X₂ - X₁)squared + (Y₂ - Y₁)squared see http://www.mathopenref.com/coorddist.html – SquiresSquire Oct 16 '12 at 09:08
  • @SquiresSquire the earth is an ellipsoid. More precise way to calculate it http://www.ngs.noaa.gov/PUBS_LIB/inverse.pdf – Gregory Kalabin Oct 16 '12 at 09:16