vnil / react-native-simple-compass

React Native module for iOS used to receive the phones heading
MIT License
42 stars 47 forks source link

Get accuracy of compass #4

Open draperunner opened 6 years ago

draperunner commented 6 years ago

In order to check whether the user needs to recalibrate the compass or not, it would be nice to get some information about the accuracy of the measurements.

It seems likenewHeading.headingAccuracy on iOS and public void onAccuracyChanged(Sensor sensor, int accuracy) on Android are the ways to get the accuracy. This could for instance be sent as a second parameter in the event handler callback: RNSimpleCompass.start(degree_update_rate, (degree, accuracy) => { ...

A problem is that "accuracy" is not the same thing on iOS and Android... Android uses four integer values, while on iOS uses floating point values that might be negative.

An alternative to getting the accuracy value is to dispatch an event when the compass is giving an invalid value, and will probably need calibration. This is when the accuracy is negative on iOS or 0 on Android.

What do you think?

pashute commented 6 years ago

@draperunner But if you DO know that it needs calibration, is there a way to calibrate it via the api ? How can I get a new calibration done (after the user moves the app in a figure 8)?

It seems no-one has dealt with this problem. For the longest time I'm getting no answer here: https://stackoverflow.com/questions/50178675/how-can-i-calibrate-the-compass-with-a-native-react-api

draperunner commented 6 years ago

@pashute If you have the compass accuracy, you know the compass has been calibrated when its accuracy is high again. You could show the calibration instruction figure while the accuracy is below your chosen threshold.

pashute commented 6 years ago

I don't understand your answer. Why will the accuracy go back up? Just by me waving the phone in a figure 8?

Actually I'm showing my ignorance here. In the first place how does the magnetometer know that it is inacurate?

בתאריך יום ד׳, 5 בספט׳ 2018, 14:05, מאת Mats Byrkjeland ‏< notifications@github.com>:

@pashute https://github.com/pashute If you have the compass accuracy, you know the compass has been calibrated when its accuracy is high again. You could show the calibration instruction figure while the accuracy is below your chosen threshold.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/vnil/react-native-simple-compass/issues/4#issuecomment-418690991, or mute the thread https://github.com/notifications/unsubscribe-auth/ABsSM4SLfbv59XdDztchbhs-KMrA-C-Oks5uX6_egaJpZM4Q2M4i .

draperunner commented 6 years ago

Yes. By moving your phone around like that, the compass will get calibrated automatically, without having to manually start a calibration process. Here's a good explanation of why it works: https://android.stackexchange.com/a/30341

pashute commented 6 years ago

and how does it know that it is out of calibration?

On Thu, Sep 6, 2018 at 11:47 AM Mats Byrkjeland notifications@github.com wrote:

Yes. By moving your phone around like that, the compass will get calibrated automatically, without having to manually start a calibration process. Here's a good explanation of why it works: https://android.stackexchange.com/a/30341

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/vnil/react-native-simple-compass/issues/4#issuecomment-419015332, or mute the thread https://github.com/notifications/unsubscribe-auth/ABsSM7eYbG136U9RSnJe7sHlVtQIfJDVks5uYOEIgaJpZM4Q2M4i .

Lelelo1 commented 5 years ago

I exposed the headingAccuracy on ios. I got a reading of 25 and sometimes 35. Nothing in between. Walking 35 mins in a city. When major disturbances in magnetic field occurred it was not reflected in the accuracy value in any way.