Skip to content

A magnetic field detector plugin. It displays the raw x, y, and z magnetometer values and a computed magnitude of the magnetic field.

Notifications You must be signed in to change notification settings

community-web-service/cordova-plugin-magnetometer

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

cordova-plugin-magnetometer

Coin Detector

A magnetic field detector plugin ideal for science toolkit or metal detector apps.

The API can be accessed via single call or by placing a listener that fires a callback function repeatedly.

It displays the raw x, y, and z magnetometer values as well as a computed magnitude of the magnetic field.

See this page for a basic sample cordova app using this plugin.

Installation

cordova plugin add https://github.com/sdesalas/cordova-plugin-magnetometer

Constants

  • cordova.plugins.magnetometer.SENSOR_DELAY_FASTEST (0 microsecond)
  • cordova.plugins.magnetometer.SENSOR_DELAY_GAME (20,000 microsecond)
  • cordova.plugins.magnetometer.SENSOR_DELAY_UI (60,000 microsecond)
  • cordova.plugins.magnetometer.SENSOR_DELAY_NORMAL (200,000 microseconds)

Methods

  • cordova.plugins.magnetometer.getReading
  • cordova.plugins.magnetometer.setSamplingPeriod
  • cordova.plugins.magnetometer.watchReadings
  • cordova.plugins.magnetometer.stop

cordova.plugins.magnetometer.setSamplingPeriod

Sets frequency in microseconds at which magnetometer sensor readings should be updated. (Note that this method is only implemented on Android)


  cordova.plugins.magnetometer.setSamplingPeriod(
    function success(reading){
      console.log(JSON.stringify(reading)); 
      // Output: {x: 23.113, y:-37.245, z:6.172, magnitude: 44.266}
    }, 
    function error(message){
     console.log(message);
    },
    cordova.plugins.magnetometer.SENSOR_DELAY_NORMAL // Constant indicating frequency in microseconds at which magnetometer sensor readings should be updated.
  )

reading object properties:

  • x
  • y
  • z
  • magnitude (calculated total - always positive)

cordova.plugins.magnetometer.getReading

Gets a single reading from the magenetometer sensor.


  cordova.plugins.magnetometer.getReading(
    function success(reading){
      console.log(JSON.stringify(reading)); 
      // Output: {x: 23.113, y:-37.245, z:6.172, magnitude: 44.266}
    }, 
    function error(message){
     console.log(message);
    }
  )

cordova.plugins.magnetometer.watchReadings

Gets regular magnetometer readings sent by the internal sensor, will fire success callback repeatedly.


  var watchID = cordova.plugins.magnetometer.watchReadings(
    function success(reading){
      console.log(JSON.stringify(reading)); 
      // Output: {x: 23.113, y:-37.245, z:6.172, magnitude: 44.266}
    }, 
    function error(message){
     console.log(message);
    },
    {frequency:40} // Frequency in ms to check magnetometer sensor readings.
  )

reading object properties:

  • x
  • y
  • z
  • magnitude (calculated total - always positive)

cordova.plugins.magnetometer.stop

Stops getting readings from the magnetometer sensor. Optional watchID parameter.


  cordova.plugins.magnetometer.stop([watchID])

Supported Platforms

  • iOS
  • Android

About

A magnetic field detector plugin. It displays the raw x, y, and z magnetometer values and a computed magnitude of the magnetic field.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 58.9%
  • Objective-C 28.8%
  • JavaScript 12.3%