Android Question compass heading for the vertical phone

Discussion in 'Android Questions' started by peacemaker, Apr 20, 2015.

  1. peacemaker

    peacemaker Well-Known Member Licensed User

    How to calculate the heading, if the phone is vertically placed ? I guess from magnetical sensor ?
     
  2. eurojam

    eurojam Well-Known Member Licensed User

  3. peacemaker

    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.
     
  4. Troberg

    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.
     
  5. peacemaker

    peacemaker Well-Known Member Licensed User

    Yes, i'm getting phone orientation already, so question is only how to compensate the compass values
     
  6. peacemaker

    peacemaker Well-Known Member Licensed User

    It seems to stupid me, that just the Z value of ORIENTATION sensor is all i need :)
     
  7. Troberg

    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.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice