getUserLocation() { let locations = {}//存放微信返回的坐标等信息 return new Promise((callback) => { let userGPS = ''//存放本机GPS状态值 this.getDeviceGPS()//获取本机GPS状态 if (locations == '') { //位置信息不存在,返回并提示 callback(true); return true; } //微信获取前后台坐标的接口:wx.startLocationUpdateBackground,这个接口申请开通后,需要搭配wx.onLocationChange来使用,使用时需要在app.json页面配置这两个接口 wx.startLocationUpdateBackground({ type: 'wgs84',//传参类型可以根据需求设置 success: (res) => { //判断是否也开通了wx.onLocationChange接口且检测本机GPS功能是否开启 if (wx.onLocationChange && this.userGPS != false) { wx.onLocationChange((res) => { callback(res);//返回结果里面包含的坐标信息对象 }); } }, fail: (err) => { if (err.errMsg == 'startLocationUpdateBackground:fail auth deny') { //未授权则返回false
微信小程序 uniapp wx.startLocationUpdateBackground前后台实时获取用户位置消息 获取用户使用设备的GPS开启状态
最新推荐文章于 2025-04-06 10:10:48 发布