- wx.getLocation调用不成功?
export const getAddress = function (wx) { let failFlag = false let latitude ="" return new Promise((resolve, reject) => { let _this = this wx.getSetting({ success: (res) => { let authSetting = res.authSetting console.log('authSetting',authSetting); if (authSetting['scope.userLocation']) { // 已授权 console.log("已授权") getLocation2(true) } else { // 未授权 console.log("未授权") getLocation2(false) } } }) function getLocation2 (userLocation) { let _this = this; let timer = setInterval(()=>{ if(!latitude &&!failFlag){ wx.showModal({ title: '警告', showCancel: false, content: '定位请求超时,请检查是否打开【手机定位】,如已开启,请尝试【退出微信重新登录】或者【重启手机】后重试!', success(res) { if (res.confirm) { wx.hideLoading(); clearInterval(timer) } } }) } },2*60*1000) wx.getLocation({ type: 'gcj02', success(res) { console.log('res',res); latitude = res.latitude clearInterval(timer) getWechatLocationInfo(res.latitude, res.longitude); }, fail() { failFlag = true clearInterval(timer) wx.hideLoading(); console.log("获取定位失败") if (!userLocation) { wx.showModal({ title: '警告', content: '您未授权地理位置信息,将无法正常使用小程序,请打开允许授权', success(res) { if (res.confirm) { openSetting() } } }) } else { wx.showModal({ title: '警告', showCancel: false, content: '获取位置信息失败,请打开手机的定位功能!', success() {} }); } } }); } // 授权 function openSetting() { let _this = this wx.openSetting({ success(res) { let authSetting = res.authSetting if (authSetting['scope.userLocation']) { // 已授权 console.log("已授权") getLocation2(true) } else { // 未授权 console.log("未授权") getLocation2(false) } } }) } function getWechatLocationInfo(latitude, longitude) { let query = { latitude: latitude, longitude: longitude }; wx.request({ url:`xxxx正常接口域名`, method: 'get', data: query, success: function (res) { let data = { ...res.data.data, address: `${res.data.data.province} ${res.data.data.city} ${res.data.data.district} ${res.data.data.sematicDescription}` } resolve(data) }, fail: function (err) { wx.hideLoading(); reject(err) } }) } }) } getLocation(e) { try { let { tip } = e.currentTarget.dataset this.setData({ tip, fileList: [] }) let _this = this; if (_this.data.localFlag) { return false; } else { wx.showLoading({ title: '定位中...' }); _this.setData({ localFlag: true }) getAddress(wx).then(res => { _this.setData({ localFlag: false }) wx.hideLoading(); let { longitude, latitude } = _this.data let data = res let form = {}; form.reportLongitude = data.longitude; form.reportLatitude = data.latitude; form.reportAreaCodes = data.provinceCode + "," + data.cityCode + "," + data.districtCode; form.reportArea = data.province + "," + data.city + "," + data.district; form.reportAddress = data.sematicDescription; longitude = data.longitude latitude = data.latitude _this.setData({ 'form.longitude': longitude, 'form.latitude': latitude, addressForm: form }) _this.checkVisitScope() }) } } catch (error) { wx.showModal({ title: '定位提示', showCancel: false, content: '' + JSON.stringify(error.message || error), }) } }, [图片][图片]相关代码,以及问题反馈截图如下,麻烦工作人员看到了回复下!
04-14 - wx.getLocation在鸿蒙系统中获取定位不成功?
[图片]
04-08 - uniapp input输入框设置focus不自动弹出输入框?
<input type="number" ref="myInput" v-model="writeInput" focus class='plateInput' @input="onInputNumber" maxlength="4" style="caret-color:transparent;" /><input type="number" ref="myInput" v-model="writeInput" focus class='plateInput' @input="onInputNumber" maxlength="4" style="caret-color:transparent;" /> 帮忙看一下什么问题导致的?
03-19 - H5中使用wx.scanQRCode掉不起来摄像头,是什么原因?
H5Z中使用wx.scanQRCode掉不起来摄像头,是什么原因?
03-05 - H5中掉起摄像头扫码是使用wx.scanCode还是wx.scanQRCode?还是两者都可?
H5中掉起摄像头扫码是使用wx.scanCode还是wx.scanQRCode?还是两者都可?
03-04 - map 中bindtap中点击地图中的任何一个点都可以吗?为啥这边不是?
<map id="map" longitude="{{longitude}}" circles="{{circles}}" show-location latitude="{{latitude}}" scale="14" bindmarkertap="handleMarkerTap" bindtap="tapMap" style="width:100%;height:90%;"></map> circles:[ { longitude: 113.324520, latitude: 23.099994, radius:500, strokeWidth:1, color:'#E41F18' } ], getDistance(lat1, lon1, lat2, lon2) { const R = 6371000; const toRad = (d) => d * Math.PI / 180; const dLat = toRad(lat2 - lat1); const dLon = toRad(lon2 - lon1); const a = Math.sin(dLat / 2) ** 2 + Math.cos(toRad(lat1)) * Math.cos(toRad(lat2)) * Math.sin(dLon / 2) ** 2; return R * (2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a))); }, isInCircle(currentLat, currentLon, circleLat, circleLon, radius) { const distance = this.getDistance(currentLat, currentLon, circleLat, circleLon); return distance <= radius; }, tapMap(e){ console.log(e,'点击地图'); const tappedLocation = e.detail; // 获取被点击的标记点的位置信息(如果有的话) if (this.isInCircle( // 22.677173,114.330154,// 内 tappedLocation.latitude,tappedLocation.longitude, this.data.circles[0].latitude, this.data.circles[0].longitude, this.data.circles[0].radius )) { // console.log('Point is within the circle'); wx.showToast({ title:'在范围内', icon:'none' }) // 处理在圆内的点击事件,例如更新markers数组等。 } else { wx.showToast({ title:'很遗憾', icon:'none' }) // console.log('Point is outside the circle'); // 可以选择移除该标记或给出提示。 } },
02-24 - 使用Skyline再使用vant组件,vant组件不能用吗?
使用Skyline再使用vant组件,vant组件不生效,原因是啥?
02-21 - 小程序发券插件如何关闭提示已放入卡券?
<!-- 发券按钮 --> <send-coupon wx:else bind:sendcoupon="getcoupon" bind:userconfirm="redirectuser" send_coupon_params="{{couponMsg.send_coupon_params}}" sign="{{couponMsg.sign}}" send_coupon_merchant="{{couponMsg.send_coupon_merchant}}" suggest_immediate_use="{{couponMsg.suggest_immediate_use}}"> <!-- 内部为自定义代码,按钮点击部分的代码写在这里 --> <!-- [[以下为示例代码 --> <view class="takeCoupon"> </view> <!-- 以上为示例代码 ]] --> </send-coupon>
2024-10-12 - video bindfullscreenchange这个事件为什么会触发两次?
<video style="width:100%;height:100%" wx:if="{{item.accept=='video'}}" id="myVideo" src="{{ele}}" show-center-play-btn="{{false}}" show-play-btn="{{true}}" catchfullscreenchange="fullscreenchange" controls class="video" ></video>
2024-09-23 - 小程序版本已发布,但发布不了扫普通链接二维码打开小程序这个规则?
[图片]
2024-09-23