# wx.onCompassChange(function callback)

Listens on the compass data change event at a frequency of 5 times per second. Listening automatically starts after the API is called. You can use wx.stopCompass to stop listening.

# Parameters

# function callback

The callback function for the compass data change event.

# Parameters

# Object res
Property Type Description Minimum Version
direction number The degree of the direction faced
accuracy number/string The accuracy 2.4.0

# Sample Code


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

# Accuracy Difference Between iOS and Android

The accuracy values are different on iOS and Android.

  • iOS: The accuracy is a number-type value indicating the deviation from the magnetic north pole. 0 indicates the device points to magnetic north, 90 east, 180 south, and so on.
  • Android: The accuracy is a string-type enumerated value.
Value Description
high High accuracy
medium Moderate accuracy
low Low accuracy
no-contact Unreliable. Connection with sensor lost.
unreliable Unreliable. Unknown error.
unknow ${value} An unknown accuracy enumerated value. That is, the value returned by the Android system is not a standard enumerated value of accuracy.
点击咨询小助手