# wx.onCompassChange(function callback)
with Promise style call: Not supported
Mini Program plugin: Not supported
Monitor compass data changes. Frequency: 5 second/Seconds, the interface will automatically start listening after the call, you can use the wx.stopCompass Stop listening.
# parameter
# function callback
Callback function for compass data change events
# parameter
# Object object
attribute | type | Introductions | Minimum version |
---|---|---|---|
direction | number | Degree of direction faced | |
accuracy | number/string | accuracy | 2.4.0 |
# sample code
wx.onCompassChange(callback)
# accuracy in iOS/Android Difference
Due to platform differences, accuracy in iOS/Android Has different values.
- iOS:accuracy It's a... number Represents a deviation from the magnetic north pole. 0 Indicates device pointing magnetic north, 90 It points east, 180. Point south, and so on.
- Android:accuracy It's a... string Is an enumerated value of the.
value | Introductions |
---|---|
high | high precision |
medium | Medium precision |
low | Low precision |
no-contact | Untrusted. Sensor lost connection. |
unreliable | Not credible, reason unknown |
unknow ${value} | An unknown precision enumeration value, that is, the Android Representing the precision returned by the system at this time value Is not a standard precision enumeration value |