my.startCompass

The my.startCompass JSAPI is called by mini program developers to start compass monitoring.

Parameters

Parameter

Data type

Required

Description

interval

String

No

The execution frequency of the callback functions that monitor compass data updates (the listeners registered with my.onCompassChange). Valid values are:

  • game: A callback frequency suitable for games, executing around every 20 ms.
  • ui: A callback frequency suitable for UI updates, executing around every 60 ms.
  • normal: A standard callback frequency, executing around every 200 ms.

If not specified, the value defaults to normal.

success

Function

No

A callback that is executed when the JSAPI call is successful.

fail

Function

No

A callback that is executed when the JSAPI call fails. When executed, it receives an err object.

complete

Function

No

A callback that is executed when the JSAPI call completes, regardless of success or failure.

err object

Parameter

Data type

Required

Description

error

Number

Yes

An error code that represents the specific error encountered.

errorMessage

String

Yes

An error message that describes the corresponding error code.

Sample code

copy
my.startCompass({
    interval: 'normal',
    success(res) {
        console.log(res)
    },
    fail(err) {
        console.log(err)
    }
});