react-native-compass-heading
react-native-compass-heading copied to clipboard
Up and Down orientation changes heading
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.
May be related: https://github.com/firofame/react-native-compass-heading/pull/14
I fixed some inconsistencies when the device is rotated to landscape, perhaps that PR helps.
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?!
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.
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)
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! 👍🏼
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).
@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).