小企业网站价格,网页上传wordpress,网站网站建设考虑要素,凡科网 小程序wx.onLocationChange(function callback) | 微信开放文档微信开发者平台文档https://developers.weixin.qq.com/miniprogram/dev/api/location/wx.onLocationChange.html
小程序 获取当前城市位置-高德地图_Start2019-CSDN博客小程序获取位置信息#xff0c;包括省市区、用户…wx.onLocationChange(function callback) | 微信开放文档微信开发者平台文档https://developers.weixin.qq.com/miniprogram/dev/api/location/wx.onLocationChange.html
小程序 获取当前城市位置-高德地图_Start2019-CSDN博客小程序获取位置信息包括省市区、用户拒绝后调起用户授权设置页重新授权获取位置信息https://blog.csdn.net/Start2019/article/details/122542917上一篇文章是获取用户所在城市地址信息这里是根据经纬度监听位置大概3秒刷新一次经纬度。
需要在app.json中配置
requiredBackgroundModes: [location],permission: {scope.userLocation: {desc: 你的位置信息将用于小程序扫描货物码时的地址展示}}, 微信小程序后台持续定位功能使用 - ShawYoi - 博客园微信小程序团队在7月30日更新了 基础库 2.8.0 其中新添加了小程序后台持续定位功能和联系定位的接口 从上到下分别是 1.wx.onLocationChange//监听位置实时变化 2.wx.sthttps://www.cnblogs.com/cokolxvd/p/11393510.html
具体做法 const app getApp();
Page({onShow: function () { this.wxLocation(); //检测是否授权位置信息若授权则开始监听位置//开启监听const _locationChangeFn res {// console.log(location change, res.latitude, res.longitude);app.getAddress(res.latitude, res.longitude)}wx.onLocationChange(_locationChangeFn); },//生命周期函数--监听页面隐藏onHide: function () {wx.offLocationChange(); //取消监听},//检测位置信息wxLocation(){wx.getSetting({success(res){ if(res.authSetting[scope.userLocationBackground]){wx.startLocationUpdate({success: (res) {console.log(startLocationUpdate-res, res)},fail: (err) {console.log(startLocationUpdate-err, err)}})} else {if(!res.authSetting[scope.userLocation]){ //打开设置页面去授权//扫描货物码时开始提示。否则取消后还是能继续扫描只有返回到该页面时才提示起不到引导用户授权效果 } else { wx.startLocationUpdate({success: (res) {console.log(startLocationUpdate-res, res)},fail: (err) {console.log(startLocationUpdate-err, err)}}) }} //判断authSetting[scope.userLocationBackground]结束}});},//点击货物码click: function(){wx.getSetting({success(res){if(!res.authSetting[scope.userLocation]){app.utils.showModal(检测到您没打开此小程序的定位权限是否去设置打开, 提示).then((){wx.openSetting({success: function(e){console.log(打开授权页面,e);app.getUserLocation(); //获取地址},})})} else {//已授权要做的操作}}});}
})
app.getAddress(res.latitude, res.longitude) 是我封装在 app.js 中的函数具体使用过程可以在上个博客中去看一下。
const amapFile require(./libs/amap-wx.130);
App({//获取用户经纬度 latitude纬度, longitude经度getUserLocation(){var that this;wx.getLocation({success: function(res){console.log(经纬度,res); // that.setData({userInfo.latitude: res.latitude, userInfo.longitude: res.longitude});that.getAddress(res.latitude,res.longitude)}})},//转换成省市区 latitude纬度long经度getAddress(latitude, longitude){// latitude22.26,longitude 112.57;var that this;var myAmapFun new amapFile.AMapWX({ key: that.addressKey }); myAmapFun.getRegeo({location: longitude , latitude ,//location的格式为经度,纬度success: function (data) {let {province,city,district} data[0].regeocodeData.addressComponent;city (city || city.length0) ? city:;console.log(省市区, province,city,district)},fail: function (info) { }})},
}) 微信小程序实时获取用户经纬度地理位置信息_电脑小技巧_上网技巧_QQ地带微信小程序实时获取用户经纬度地理位置信息https://www.oicqzone.com/pc/2019092024670.html