All Products
Search
Document Center

Mobile Platform as a Service:Gyroscope

Last Updated:Sep 04, 2023

my.onGyroscopeChange(function callback)

Note

This interface is only supported in base library 1.9.0 or later versions and mPaaS V10.1.60 or later versions. For earlier versions, you need to perform compatibility processing. See Instructions on Mini Program base library.

This interface is used to listen to the gyroscope data change events. The interface starts listening to the events automatically once called. The callback interval is 500 ms. You can use my.offGyroscopeChange() to stop listening.

Parameters

Name

Type

Description

function

callback

Callback function for the events of gyroscope data changes.

Callback return parameters

Name

Type

Description

x

Number

Angular velocity in X-axis direction

y

Number

Angular velocity in Y-axis direction

z

Number

Angular velocity in Z-axis direction

Sample code

my.onGyroscopeChange((res)=>{
   console.log('gyroData.rotationRate.x = ' + res.x);
   console.log('gyroData.rotationRate.y = ' + res.y);
   console.log('gyroData.rotationRate.z = ' + res.z);
});

my.offGyroscopeChange()

Note

This interface is only supported in base library 1.9.0 or later versions and mPaaS V10.1.60 or later versions. For earlier versions, you need to perform compatibility processing. See Instructions on Mini Program base library.

Rhis interface is used to stop listening to gyroscope data.

Sample code

my.offGyroscopeChange();

Whether to pass callback value

  • If no callback value is passed, listeners on all event callback will be removed. See the following code example:

      my.offGyroscopeChange();
  • If the callback value is passed, only the corresponding callback events will be removed. See the following code example:

      my.offGyroscopeChange(this.callback);