title: Taro.onLocationChange(callback)
sidebar_label: onLocationChange
Listens for real-time geolocation change events, to be used in conjunction with Taro.startLocationUpdateBackground
、Taro.startLocationUpdate
.
Type
(callback: Callback) => void
Parameters
Callback
Callback function for real-time geolocation change events.
(result: CallbackResult) => void
Property | Type |
---|---|
result | CallbackResult |
CallbackResult
Property | Type | Description |
---|---|---|
accuracy | number |
Location accuracy |
altitude | number |
Altitude (in m) |
horizontalAccuracy | number |
Horizontal accuracy (in m) |
latitude | number |
Latitude. The value ranges from -90 to +90, and the negative number means south latitude. |
longitude | number |
Longitude. The value ranges from -180 to +180, and the negative number means west longitude. |
speed | number |
Speed (in m/s) |
verticalAccuracy | number |
Vertical accuracy (in m) (Not available for Android, and 0 will be returned) |
Sample Code
const _locationChangeFn = function (res) {
console.log('location change', res)
}
Taro.onLocationChange(_locationChangeFn)
Taro.offLocationChange(_locationChangeFn)
API Support
API | WeChat Mini-Program | H5 | React Native |
---|---|---|---|
Taro.onLocationChange | ✔️ |