WeChat Open Platform

Mini Programs Documentation

Compass

wx.onCompassChange(CALLBACK)

Monitors compass data. Frequency: 5 times/second. Monitoring will start automatically after the interface is called. wx.stopCompass can be used to stop monitoring.

CALLBACK return parameters:

Parameter Type Description
direction Number Number of degrees in direction faced

Sample code:

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

wx.startCompass(OBJECT)

Starts monitoring compass data.

OBJECT parameter descriptions:

Parameter Type Required Description
success Function No Callback function for successful interface call
fail Function No Callback function for failed interface call
complete Function No Callback function for interface call results (will be executed if call succeeds or fails)

Sample code:

wx.startCompass()

wx.stopCompass(OBJECT)

Stops monitoring compass data.

OBJECT parameter descriptions:

Parameter Type Required Description
success Function No Callback function for successful interface call
fail Function No Callback function for failed interface call
complete Function No Callback function for interface call results (will be executed if call succeeds or fails)

Sample code:

wx.stopCompass()