Android Question How to get compass working with GPS

Scantech

Well-Known Member
Licensed User
Longtime User
I am using Location1.Bearing to read the value and it is always 0. Tested with Samsung S6. Is there a way to get the compass direction?
 

emexes

Expert
Licensed User
The signal was weak. I was indoor.
Plus you usually have to move a bit. GPS tells you which direction you are moving, not which direction you are facing. Usually it becomes valid when the GPS speed becomes valid too.

If you need to know which direction you are facing, ie, the orientation of the phone, then the magnetometers will get you most of the way there, just don't go staking your life on the readings. I assume Android will translate the magnetic flux readings into a NSEW bearing, but I'd be (pleasantly) surprised if it took into account the magnetic declination of true/geographic vs magnetic north, which varies depending on where you are. Nearby ferrous objects (eg, car bodies, concrete steel reinforcement) and electromagnetic fields don't help.
 
Upvote 0

emexes

Expert
Licensed User
magnetometers will get you most of the way there
Once you do have a reasonably good directional fix, you could use the gyroscopes to keep ahold of that... except that gyroscopes don't seem to be common on Android phones. Phones that support VR should have them, Samsung seems to be good in that regard.
 
Upvote 0

emexes

Expert
Licensed User
Usually it becomes valid when the GPS speed becomes valid too.

upload_2019-8-13_20-34-1.png


although I still suspect that BearingValid and SpeedValid follow each other closely, because they would both be derived by Doppler techniques, rather than the time-of-flight ranging used for calculating position.
 
Upvote 0

emexes

Expert
Licensed User
Doppler is not related. It calculates the speed and bearing based on the changes in the position.

https://racelogic.support/01VBOX_Automotive/01General_Information/Knowledge_Base/How_Does_GPS_Work?

There is a common misconception that speed measured via GPS is done so as a function of position against time. If this were the case, GPS velocity would be just about unusable, because GPS position relies on precise measurements of the distance from the receiver to the satellite, and therefore suffers from numerous effects - such as atmospheric interference - which delays the signal.

Fortunately, velocity isn't measured like this: instead, the Doppler shift in the signals coming from the satellites is captured and this leads to an incredibly accurate measurement of speed.
 
Last edited:
Upvote 0

emexes

Expert
Licensed User
I've learned something today.
Well, that makes me a winner (I think) because I learned two things today:

1/ Arduino ticks are indeed 1000 ms (at least, as measured on my ESP32's here) whereas I was pretty sure they were 1024 ms thanks to "decimal" system clock frequencies and binary division timers.

2/ B4R stacks (still getting my head around those)
 
Upvote 0
Top