Get correct device's orientation


Hello, I wanna make a GPS-Like App, for this I am using the ‘Device Orientation’ plugin.

What I want is that when the user turns to right or to left (90º), the whole map will move to the same direction and if the user moves 45º then only his position marker will move also 45º in the same direction.

My problem comes to when rotating either the map or the marker, they’re movin when they shouldn’t (before time). Idk if this is the plugin I need for what I want.

My code is:

this.deviceOrientation.watchHeading().subscribe(orientation => {
        if (!this.lastMapHeading) this.lastMapHeading = orientation.magneticHeading;
        if (!this.lastMarkerHeading) this.lastMarkerHeading = orientation.magneticHeading;
          if (Math.abs(this.lastMarkerHeading - orientation.magneticHeading) >= 45) {
            if (this.lastMarkerHeading - orientation.magneticHeading >= 0) this.marker.setRotation(-45);
            else this.marker.setRotation(45);
            this.lastMarkerHeading = orientation.magneticHeading;
          } else if (Math.abs(this.lastMapHeading - orientation.magneticHeading) >= 90) {
            let cameraPosition =;
            cameraPosition.duration = 500;
            if (this.lastMapHeading - orientation.magneticHeading >= 0) cameraPosition.bearing = -90;
            else cameraPosition.bearing = 90;
            this.lastMapHeading = orientation.magneticHeading;

Does anyone know how to achieve this? I don’t know if I should make use of the accelerometer too.



Hi, Kyrax80. You were able to fix your problem? I need a solution for a similar application


No, I wasn’t able to find a way, sorry