How to get Android phone orientation matching human orientation?

后端 未结 4 1379
有刺的猬
有刺的猬 2021-01-31 17:30

I\'m making a map app, including the location arrow that shows you which way you\'re facing, like so:

\"Map

4条回答
  •  一生所求
    2021-01-31 18:03

    It seems that the appropriate way to get the bearing when the user is holding the phone vertically is to use something like this:

    // after calling getRotationMatrix pass the rotationMatix below:
    SensorManager.remapCoordinateSystem(inR, AXIS_X, AXIS_Z, outR);
    

    If you want to handle both ways (vertical and flat) you will probably need to detect that and then only perform this remap when it is vertical.

    See the API Documentation here.

提交回复
热议问题