title: Taro.onLocationChange(callback)

sidebar_label: onLocationChange

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

Reference

Type

  1. (callback: Callback) => void

Parameters

Callback

Callback function for real-time geolocation change events.

  1. (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

  1. const _locationChangeFn = function (res) {
  2. console.log('location change', res)
  3. }
  4. Taro.onLocationChange(_locationChangeFn)
  5. Taro.offLocationChange(_locationChangeFn)

API Support

API WeChat Mini-Program H5 React Native
Taro.onLocationChange ✔️