Skip to content

Commit e55eaac

Browse files
authored
Merge pull request yonahforst#6 from zsajjad/PerpendicularHeading
[Android] Corrected heading for perpendicular device
2 parents c1b2a4c + 202c1d3 commit e55eaac

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

android/src/main/java/com/joshblour/reactnativeheading/ReactNativeHeadingModule.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ public class ReactNativeHeadingModule extends ReactContextBaseJavaModule impleme
3636

3737
private static Context mApplicationContext;
3838
private int mAzimuth = 0; // degree
39-
private int mFilter = 5;
39+
private int newAzimuth = 0; // degree
40+
private float mFilter = 5;
4041
private SensorManager mSensorManager;
4142
private Sensor mSensor;
4243
private float[] orientation = new float[3];
@@ -82,21 +83,21 @@ public void onSensorChanged(SensorEvent event) {
8283
// calculate th rotation matrix
8384
SensorManager.getRotationMatrixFromVector(rMat, event.values);
8485
// 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;
8788
//dont react to changes smaller than the filter value
8889
if (Math.abs(mAzimuth - newAzimuth) < mFilter) {
8990
return;
9091
}
9192

92-
mAzimuth = newAzimuth;
93-
Log.e("TAG", String.valueOf(newAzimuth));
94-
WritableMap params = Arguments.createMap();
95-
params.putInt("heading", mAzimuth);
96-
9793
getReactApplicationContext()
9894
.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+
//
100101
}
101102
}
102103

0 commit comments

Comments
 (0)