tencent cloud

All product documents
Tencent Cloud Super App as a Service
Last updated: 2025-04-10 18:18:36
Compass
Last updated: 2025-04-10 18:18:36

startCompass

This API is called using wx.startCompass(Object object).
Feature description:Starts listening for compass data.
Parameter and description:Object object.
Property
Type
Default value
‍Required
Description
success
function
-
False
Callback function for successful API calls.
fail
function
-
False
Callback function for failed API calls.
complete
function
-
False
Callback function executed after API call ends (regardless of success or failure).
Example:
wx.startCompass()

stopCompass

This API is called using wx.stopCompass(Object object).
Feature description:Stops listening for compass data.
Parameter and description:Object object.
Property
Type
Default value
‍Required
Description
success
function
-
False
Callback function for successful API calls.
fail
function
-
False
Callback function for failed API calls.
complete
function
-
False
Callback function executed after API call ends (regardless of success or failure).
Example
wx.stopCompass()

onCompassChange

This API is called using wx.onCompassChange(function listener).
Feature description:Listens for compass data change event. Frequency: 5 times per second. Automatically starts listening after the API call, and can be stopped using wx.stopCompass.
Parameter and description:function listener. The callback function for compass data change event. Parameter: Object res.
Property
Type
Description
direction
number
The direction in degrees.
accuracy
number/string
The accuracy.
Example
wx.onCompassChange(function (res) {
console.log(res.direction)
})
The accuracy difference on iOS and Android:Due to platform differences, the accuracy has different values on iOS and Android.
iOS: The accuracy is is a number representing the deviation from magnetic north. 0 means the device points to magnetic north, 90 means east, 180 means south, and so on.
Android: accuracy is a string representing an enumerated value.
Value
Description
high
High accuracy.
medium
Medium accuracy.
low
Low accuracy.
no-contact
Unreliable. The sensor connection is lost.
unreliable
Unreliable for unknown reasons.
unknow ${value}
Unknown accuracy enumeration value, meaning the value returned by the Android system is not a standard accuracy enumeration value.

offCompassChange

This API is called using wx.offCompassChange(function listener).
Feature description:Removes the listener for compass data change event.
Parameter and description:function listener. The listener passed to onCompassChange. If not provided, all listeners will be removed.
Example:
const listener = function (res) { console.log(res) }

wx.onCompassChange(listener)
wx.offCompassChange(listener) // Must pass the same function object used in onCompassChange


Was this page helpful?
You can also Contact Sales or Submit a Ticket for help.
Yes
No

Feedback

Contact Us

Contact our sales team or business advisors to help your business.

Technical Support

Open a ticket if you're looking for further assistance. Our Ticket is 7x24 available.

7x24 Phone Support
Hong Kong, China
+852 800 906 020 (Toll Free)
United States
+1 844 606 0804 (Toll Free)
United Kingdom
+44 808 196 4551 (Toll Free)
Canada
+1 888 605 7930 (Toll Free)
Australia
+61 1300 986 386 (Toll Free)
EdgeOne hotline
+852 300 80699
More local hotlines coming soon