Android Question compass heading for the vertical phone

peacemaker

Well-Known Member
Licensed User
How to calculate the heading, if the phone is vertically placed ? I guess from magnetical sensor ?
 

peacemaker

Well-Known Member
Licensed User
Thanks, but what are the final digits ? Degree angles ?
I need the compass heading, but not by ORIENTATION sensor at horizontal phone position - but the same compass heading if phne is vertically placed.
 

Troberg

Well-Known Member
Licensed User
Ideally, one would use accellerometer sensors to determine device rotation, and then use that to compensate the compass. Probably not that hard, but I'm too tired to do the math at the moment.
 

peacemaker

Well-Known Member
Licensed User
Yes, i'm getting phone orientation already, so question is only how to compensate the compass values
 

peacemaker

Well-Known Member
Licensed User
It seems to stupid me, that just the Z value of ORIENTATION sensor is all i need :)
 

Troberg

Well-Known Member
Licensed User
Well, it all depends. If you are only using the phone in a perfectly upright position, that's enough. However, users frequently tilt the device, so it mihgt be prudent to use a full orientation.

What you need to do is to use accelerometers to find down. From down, it's easy to find forward, it's 90 degrees off down in the forward/up direction.

Then, you get the three orientation values to get a 3D vector. Project that vector on the forward direction, and you'll have a heading that works regardless of device orientation.

However, be aware that the magnetic sensor is usually extremely fickle, don't rely on it to be accurate, even under the best of circumstances. If the device is moving, you'll get a much more accurate reading from the GPS, which simply calculates the direction between current and previous positions.
 
Top