All Products
Search
Document Center

Mobile Platform as a Service:Accelerometer

Last Updated:Feb 04, 2021

my.onAccelerometerChange(function callback)

Note:
  • This interface is supported since basic library version 1.9.0. Compatibility processing is required for earlier versions. See Mini Program base library to learn more.
  • This interface is only supported in mPaaS 10.1.60 and later versions.

The interface is used to listen to the acceleration data. The callback interval is 500ms. After the interface is called, the listening is automatically started. You can use my.offAccelerometerChange to stop listening.

Parameters

Parameter Type Description
function callback Callback function for the acceleration data change events.

Callback return value

Parameter Type Description
x Number X axis
y Number Y axis
z Number Z axis

Sample code

  1. my.onAccelerometerChange(function(res) {
  2. console.log(res.x)
  3. console.log(res.y)
  4. console.log(res.z)
  5. })

my.offAccelerometerChange()

Note:
  • This interface is supported since basic library version 1.9.0. Compatibility processing is required for earlier versions. See Mini Program base library to learn more.
  • This interface is only supported in mPaaS 10.1.60 and later versions.

This interface is used to stop listening to acceleration data.

Sample code

  1. my.offAccelerometerChange()

Whether to pass callback value or not

  • If the callback value is not passed, the callbacks of all events will be removed. The sample code is as follows:
    1. my.offAccelerometerChange();
  • If the callback value is passed, only the corresponding callback is removed. The sample code is as follows:
    1. my.offAccelerometerChange(this.callback);