Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

WeChat Small Program API-Device-Comptrot


May 19, 2021 WeChat Mini Program Development Document


Table of contents


wx.onCompassChange(CALLBACK)

Listen to compass data, frequency: 5 times per second, the interface call will automatically start listening, wx.stopCompass stop listening.

CALLBACK returns parameters:

Parameters Type Description
direction Number The degree of direction faced

Example code:

wx.onCompassChange(function (res) {
  console.log(res.direction)
})

wx.startCompass(OBJECT)

Base library 1.1.0 starts to support, and low versions need to be compatible

Start listening to the arospass data.

OBJECT parameter description:

Parameters Type Required Description
success Function Whether The interface calls a successful callback function
fail Function Whether The interface calls the failed callback function
complete Function Whether Callback function at end of interface call (call succeeds, fails are executed)

Example code:

wx.startCompass()

wx.stopCompass(OBJECT)

Base library 1.1.0 starts to support, and low versions need to be compatible

Stop listening to the arospass data.

OBJECT parameter description:

Parameters Type Required Description
success Function Whether The interface calls a successful callback function
fail Function Whether The interface calls the failed callback function
complete Function Whether Callback function at end of interface call (call succeeds, fails are executed)

Example code:

wx.stopCompass()

wx.offCompassChange(function callback)


Base Library 2.9.3 starts to support, and low versions need to be compatible

Cancels listening for ppon data change events, with empty parameters, cancels all event listening.

Parameters

function callback

The callback function for the pprow data change event