Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

WeChat small program API listens to real-time geolocation


May 19, 2021 WeChat Mini Program Development Document


Table of contents


wx.onLocationChange(function callback)

Base library 2.8.1 starts to support, and low versions need to be compatible.

Listening for real-time geo-location change events needs to be used in conjunction with wx.startLocationUpdate, wx.startLocationUpdate.

Parameters

function callback

A callback function for real-time geo-change events

Parameters

Object res
Property Type Description The lowest version
latitude number Latitudes, ranging from -90 to 90, with negative numbers representing south latitudes
longitude number Longe longs, ranging from -180 to 180, with negative numbers representing the western long term
speed number Speed, unit m/s
accuracy number The accuracy of the position
altitude number Height, unit m 1.2.0
verticalAccuracy number Vertical accuracy, unit m (Android can't get, return 0) 1.2.0
horizontalAccuracy number Horizontal accuracy, unit m 1.2.0

The sample code

 const _locationChangeFn = function(res) {
  console.log('location change', res)
 }
 wx.onLocationChange(_locationChangeFn)
 wx.offLocationChange(_locationChangeFn)

wx.offLocationChange(function callback)

Base library 2.8.1 starts to support, and low versions need to be compatible.

Cancel listening for real-time geo-location change events

Parameters

function callback

A callback function for real-time geo-change events