0

When the user starts his mobile phone at a certain point as the starting position, how can i get the trajectory of the mobile phone movement?

The function I expected to implement is: users can use his mobile phone as a brush.

I am using React Native / Javascript.

I found this package: https://www.npmjs.com/package/react-native-sensors

The function it provides seems to solve my problem.

I tested accelerometer, gyroscope, magnetometer on Android,

import { accelerometer } from "react-native-sensors";

const subscription = accelerometer.subscribe(({ x, y, z, timestamp }) =>
  console.log({ x, y, z, timestamp })
);

When my mobile phone is prohibited, the value obtained is constantly changing, and the difference is very large.

Moreover, I don't know how to use the data obtained to calculate the movement trajectory of the mobile phone.

In addition, I also tested DeviceOrientation and DeviceMotionEvent on web page.

window.addEventListener("deviceorientation", function(event) {
    var rotateDegrees = event.alpha;
    var leftToRight = event.gamma;
    var frontToBack = event.beta;
    handleOrientationEvent(frontToBack, leftToRight, rotateDegrees);
}, true);

window.addEventListener('devicemotion', function(event) {
    handlerMemotion(event.acceleration.x, event.acceleration.y, event.acceleration.z);
});

The data obtained through the DeviceOrientation event is correct, can get the angle of the mobile phone rotation from these data.

But the data obtained through the DeviceMotion event has been constantly changing, even when the mobile phone is still in static.

What should I do? Is there a better package / library?

0 Answers0