How do I detect if phone is being held straight up or lying horizontal or tilted?

Viewed 21

I am trying to try and constrain shooting pictures when the phone is held (approximately) straight. The purpose here is to ensure - for example - that a facade, something lying on a horizontal surface is being shot straight.

I am using to detect changes in angles and I have come to the conclusion that:

  • beta and gamma close to 0: phone is held flat horizontal (parallel to a floor)
  • beta close to 0 and gamma close to 90: phone is held in landscape mode
  • beta and gamma close to 90: phone held in portrait mode

Is this correct? Right now I am testing on iOS - but I'd be interested to know if this changes depending on platforms.

1 Answers

Provide some extra information, like the platform you're writing this code for. If you have access to the devices UI, you could try to compare the width and height of the window/viewport. If the width is greater than the height, it's in landscape.

Related