Skip to main content
Version: 3.x

Taro.onLocationChange(callback)

Listens for real-time geolocation change events, to be used in conjunction with Taro.startLocationUpdateBackgroundTaro.startLocationUpdate.

Reference

Type

(callback: Callback) => void

Parameters

Callback

Callback function for real-time geolocation change events.

(result: CallbackResult) => void
PropertyType
resultCallbackResult

CallbackResult

PropertyTypeDescription
accuracynumberLocation accuracy
altitudenumberAltitude (in m)
horizontalAccuracynumberHorizontal accuracy (in m)
latitudenumberLatitude. The value ranges from -90 to +90, and the negative number means south latitude.
longitudenumberLongitude. The value ranges from -180 to +180, and the negative number means west longitude.
speednumberSpeed (in m/s)
verticalAccuracynumberVertical 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

APIWeChat Mini-ProgramH5React Native
Taro.onLocationChange✔️