Android Question PhoneOrientation and phone orientation

jccraig

Member
Licensed User
My goal is to have a flat compass, simulating a floating needle, and also a compass to show the azimuth, or compass direction, of a picture as it is taken.

I'm using the PhoneOrientation object to get the phone's azimuth. Here's where I grab that data...

B4X:
Sub Orientation_OrientationChanged (Azimuth As Float, Pitch As Float, Roll As Float)

Is the azimuth accurate when the phone is held flat, with the camera facing the center of the earth, and also accurate when the phone is vertical, with the camera facing the horizon? In other words, is the azimuth accurate when the Pitch is at zero and at 90 degrees?

I seem to get different quality of results in these two phone orientations, so I'm wondering if the library code correctly switches between X,Y magnetic axes to calculate orientation when flat, and then to X,Z (or perhaps Y,Z) axes when held vertical.
 

derez

Expert
Licensed User
I use this on nexus 5 and it works horizontal or vertical however the results may vary per the device:
B4X:
Sub Orientation_OrientationChanged (Azimuth As Float, Pitch As Float, Roll As Float)
    Nangle = Azimuth
End Sub

Sub tmr_tick
    setRotation(compass,-Nangle)
    azlbl.Text = NumberFormat(Nangle,3,0)
End Sub
 
Upvote 0
Top