@@ -36,7 +36,8 @@ public class ReactNativeHeadingModule extends ReactContextBaseJavaModule impleme
36
36
37
37
private static Context mApplicationContext ;
38
38
private int mAzimuth = 0 ; // degree
39
- private int mFilter = 5 ;
39
+ private int newAzimuth = 0 ; // degree
40
+ private float mFilter = 5 ;
40
41
private SensorManager mSensorManager ;
41
42
private Sensor mSensor ;
42
43
private float [] orientation = new float [3 ];
@@ -82,21 +83,21 @@ public void onSensorChanged(SensorEvent event) {
82
83
// calculate th rotation matrix
83
84
SensorManager .getRotationMatrixFromVector (rMat , event .values );
84
85
// get the azimuth value (orientation[0]) in degree
85
- int newAzimuth = (int ) ( Math .toDegrees ( SensorManager .getOrientation ( rMat , orientation )[0 ] ) + 360 ) % 360 ;
86
-
86
+ newAzimuth = (((( Math .toDegrees ( SensorManager .getOrientation ( rMat , orientation )[0 ] ) + 360 ) % 360 ) -
87
+ ( Math . toDegrees ( SensorManager . getOrientation ( rMat , orientation )[ 2 ] ))) + 360 ) % 360 ;
87
88
//dont react to changes smaller than the filter value
88
89
if (Math .abs (mAzimuth - newAzimuth ) < mFilter ) {
89
90
return ;
90
91
}
91
92
92
- mAzimuth = newAzimuth ;
93
- Log .e ("TAG" , String .valueOf (newAzimuth ));
94
- WritableMap params = Arguments .createMap ();
95
- params .putInt ("heading" , mAzimuth );
96
-
97
93
getReactApplicationContext ()
98
94
.getJSModule (DeviceEventManagerModule .RCTDeviceEventEmitter .class )
99
- .emit ("headingUpdated" , params );
95
+ .emit ("headingUpdated" , (int ) newAzimuth );
96
+
97
+ mAzimuth = newAzimuth ;
98
+ // Log.e("Azimuth",
99
+ // String.valueOf(newAzimuth));
100
+ //
100
101
}
101
102
}
102
103
0 commit comments