0

I need to get the device orientation to make some kind of compass. I saw that the old plugin | [2] used for this is now deprecated and that is suggested to use the W3C Device Orientation API now.

I tried to use it this way:

this.window.addEventListener("deviceorientation", function(event) {
    console.log(event);
}, true);

but the main orientation values (alpha, beta and gamma) are always null. I tried to turn on the GPS too see if anything changes, but does not.

I tried other events related to changes of orientation, but these don't even fire, I belive this is because the orientation values are always null.

this.window.addEventListener("orientationchange", (event) => {
    console.log(event, screen.orientation.angle);                       
}, true);

this.window.onorientationchange = (event) => { 
    console.log(event, screen.orientation.angle);
};

Am I doing something wrong? Is there other easier or correct way to get these informations?

leonardofmed
  • 842
  • 3
  • 13
  • 47
  • Well, I tried to use the deprecated plugin anyway and it gives me error code 3 when I try to use. [Checking the docs](https://github.com/apache/cordova-plugin-device-orientation/blob/master/src/android/CompassListener.java#L180) I can see that it's because the plugin can't find the magnetic sensor of my device. So, as stated [here](https://stackoverflow.com/a/29062279/7123439), either my device does not have a magnetic sensor, or the vendor has not implemented support for it in the OS. – leonardofmed Mar 30 '20 at 12:09

1 Answers1

0

In my case, the problem occurs because my device does not support magnetic sensor (Samsung Galaxy E5)

leonardofmed
  • 842
  • 3
  • 13
  • 47