Search docs/
Getting StartedPlugins

Device eMagnetometer

Requires Cordova plugin: cordova-plugin-magnetometer. For more info, please see the Device Orientation docs.

Stuck on a Cordova issue?

If you're building a serious project, you can't afford to spend hours troubleshooting. Ionic’s experts offer premium advisory services for both community plugins and premier plugins.

Contact Us Today!


npm install cordova-plugin-magnetometernpm install @ionic-native/magnetometerionic cap syncionic cordova plugin add cordova-plugin-magnetometernpm install @ionic-native/magnetometer
Ionic Enterprise comes with fully supported and maintained plugins from the Ionic Team. Learn More or if you're interested in an enterprise version of this plugin Contact Us

Supported Platforms

  • Android
  • iOS



See here.


// DeviceOrientationCompassHeading is an interface for compass
import { Magnetometer, MagnetometerReading } from '@ionic-native/device-orientation/ngx';

constructor(private magnetometer: Magnetometer) { }


// Get the device current compass heading
  (data: MagnetometerReading) => console.log(data),
  (error: any) => console.log(error)

// Watch the device compass heading change
var subscription = this.deviceOrientation.watchReadings().subscribe(
  (data: MagnetometerReading) => console.log(data)

// Stop watching heading change