Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Up and Down orientation changes heading #18

Open
jahau opened this issue Apr 26, 2021 · 7 comments
Open

Up and Down orientation changes heading #18

jahau opened this issue Apr 26, 2021 · 7 comments

Comments

@jahau
Copy link

jahau commented Apr 26, 2021

Is it by design that up and down movement (z changes) orientation changes also the compass value? Or is it just a bug with React Native 0.64.0? Thanks.

@cristianoccazinsp
Copy link
Contributor

May be related: #14

I fixed some inconsistencies when the device is rotated to landscape, perhaps that PR helps.

@jahau
Copy link
Author

jahau commented May 6, 2021

It doesn't seem to be working, still the same observations. The phone isn't rotated to landscape in this case at all. It just gives funny values when leaning back or forwards. Shouldn't it give always the same heading value in this case? Just think about the real use-case, when adapting this library e.g. show compass on apps. The compass direction should not change if you change the angle of the phone, right?!

@cristianoccazinsp
Copy link
Contributor

I see, that is probably something different then. Do you see this in iOS, Android, or both? I know iOS has a bunch of options to tell it what's the origin so you could handle phone movements. For Android, however, I'm afraid it will most likely need some math expert to solve it as it is purely done in code without any help from the OS.

@cristianoccazinsp
Copy link
Contributor

Just gave it a quick test and it seems like it happens only on Android? Seems to be working as you would expect in iOS (same orientation with the phone almost vertical and almost flat)

@the-habu
Copy link

From my experience, it seems to work better in this library then in others I've tried.
I did however find this stackoverflow answer which might be worth trying. It's by a mathematician with very high reputation. The comments to the answer however would suggest that it delivers similar quality to your implementation.
Sadly, I don't understand it yet as working with sensors is another thing to me... but if I try it myself I will make it a PR for sure.

Thank you for the lib and your support so far! 👍🏼

@jahau
Copy link
Author

jahau commented May 14, 2021

Just gave it a quick test and it seems like it happens only on Android? Seems to be working as you would expect in iOS (same orientation with the phone almost vertical and almost flat)

Yes, doesn't work on Android. I haven't tried on iOS but it's most likely as you described...works on iOS but not on Android. There seems to be always some differences between these platforms, e.g. the sensor values in Android have to be multiplied by -9.81 in order to get comparable results to iOS (you can google why it's like this).

@cristianoccazinsp
Copy link
Contributor

@jahau the difference is that the iOS version of the code relies entirely on the framework (no math, no odd sensor usage, just a simple query). On the other hand, the Android version has to combine 2 or 3 different sensors data (manually), multiply some matrices and do a bunch of things to get the value.

When I reviewed the android code, I looked into a bunch of alternatives and different SO questions and the code was more or less always the same, so I don't know what could be missing. Alternatively, the android version could try to use the GPS/Location libraries, but that would sadly require user location permission (I gave it a quick try a while ago and it was really bad too).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants