0

I'm developing an app that is required to get device orientation to know what the direction the users are going, even they are stopped. But many smartphones don't have the compass sensor, then I need to get the accelerometer and gyroscope data.

So, how can I get the device orientation using these sensors? I've already read some similar questions (here) , but it was applied to Android native, and it has a event.values that returns an array that I don't know how to get using Ionic plugins.

jraspante
  • 228
  • 4
  • 19

2 Answers2

0

You can use ionic native Gyroscope plugin for this,

$ ionic cordova plugin add cordova-plugin-gyroscope
$ npm install --save @ionic-native/gyroscope
AddWeb Solution Pvt Ltd
  • 21,025
  • 5
  • 26
  • 57
0

You can use the Platform service.

Important: orientation checking must be done after the platform becomes ready. Sample code in a .ts file:

import { Platform } from 'ionic-angular';

@Component({...})
export MyPage {
  constructor(public platform: Platform) {

      this.platform.ready().then(() => {
            if (this.platform.isPortrait())
                // Do something

            if (this.platform.isLandscape())
                // Do something
      });

  }
}
elenche
  • 171
  • 2
  • 7