wx.onLocationChange //监听位置实时变化
wx.stopLocationUpdate //关闭监听位置变化,前后台都不接收
wx.startLocationUpdate //开启小程序进入前台接收位置消息
wx.startLocationUpdataBackground //小程序进入前后台均接收消息
做好持续定位功能条件:
1、在app.json中加入,才能在后台调用定位功能
"requiredBackgroundModes": [
"location"
],
2、在页面加入所用到的API
wx.startLocationUpdateBackground({
success(res) {
console.log('开启后台定位', res)
},
fail(res) {
console.log('开启后台定位失败', res)
}
})
此API无法用开发工具测试,需采用真机测试
3、在测试页面调用wx.onLocationChange获取实时位置变化
wx.onLocationChange(function(res) {
console.log(‘location change’, res)
})