Magnetometer.z
The z
read-only property of the Magnetometer
interface returns a double-precision integer containing the magnetic field around the device's z axis.
If a feature policy blocks use of a feature it is because your code is inconsistent with the policies set on your server. This is not something that would ever be shown to a user. The Feature-Policy
HTTP header article contains implementation instructions.
Syntax
var magnetometerz = magnetometer.z
Value
A Number
.
Example
The magnetometer is typically read in the Sensor.onreading
event callback. In the example below this occurs sixty times a second.
let magSensor = new Magnetometer({frequency: 60}); magSensor.addEventListener('reading', e => { console.log("Magnetic field along the X-axis " + magSensor.x); console.log("Magnetic field along the Y-axis " + magSensor.y); console.log("Magnetic field along the Z-axis " + magSensor.z); }); magSensor.start();
Specifications
Specification |
---|
Magnetometer # magnetometer-z |
Browser compatibility
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | |
z |
56 |
79 |
No |
No |
43 |
No |
No |
56 |
No |
43 |
No |
No |
© 2005–2021 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/Magnetometer/z