微信小程序实时监听位置变化api的使用
1.在需要使用位置跟踪的页面使用
wx.onLocationChange(function (res) {
console.log(res, '实时监听位置')
that.setData({
longitude: res.longitude,
latitude: res.latitude,
})
})
wx.startLocationUpdate({
success: (res) => {
console.log(res, '启动位置跟踪')
},
})
onUnload: function () {
// 停止位置跟踪
wx.stopLocationUpdate({
success: (res) => {
console.log("onUnload stopLocationUpdate success", res)
},
fail: (err) => {
console.log("onUnload stopLocationUpdate fail", err)
}
})
}