From 2a5bbb1e2a19fa24255a686b3e57eada0df32ed2 Mon Sep 17 00:00:00 2001 From: dengj <209192278@qq.com> Date: Tue, 7 Nov 2023 10:55:04 +0800 Subject: [PATCH] =?UTF-8?q?=E9=82=93=E6=B4=81=EF=BC=9A=E4=BD=8D=E7=BD=AE?= =?UTF-8?q?=E5=AE=9A=E4=BD=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/InputAndSwiper/InputAndSwiper.vue | 67 +++++++++++++------- 1 file changed, 45 insertions(+), 22 deletions(-) diff --git a/components/InputAndSwiper/InputAndSwiper.vue b/components/InputAndSwiper/InputAndSwiper.vue index 6697869..1428a6a 100644 --- a/components/InputAndSwiper/InputAndSwiper.vue +++ b/components/InputAndSwiper/InputAndSwiper.vue @@ -31,62 +31,85 @@ "https://alifei01.cfp.cn/creative/vcg/800/new/VCG41175510742.jpg" ] } - }, - position: { - type: String, - default () { - return '定位' - } } }, data() { return { - + position: '定位1' }; }, options: { styleIsolation: 'shared', // 解除样式隔离 }, created() { - // this.getLocation() + this.open() }, methods: { - getLocation() { + getLocation1() { + let qqmapsdk = new QQMapWX({ + key: 'ZRKBZ-Q7FWL-GVZPK-MCRBU-4XFB5-ATBDB' + }); uni.getLocation({ type: 'wgs84', // geocode: true, // 返回城市信息 // enableHighAccuracy: false, // 开启高精度模式 success: function(res) { - let qqmapsdk = new QQMapWX({ - key: 'ZRKBZ-Q7FWL-GVZPK-MCRBU-4XFB5-ATBDB' - }); + console.log('res.latitude', res.latitude); + console.log('res.longitude', res.longitude); qqmapsdk.reverseGeocoder({ location: { latitude: res.latitude, longitude: res.longitude }, success: (re) => { + console.log("解析地址成功", res); console.log(re.result.ad_info.city, '成都市=='); console.log(re.result.ad_info.district, '武侯区=='); + this.position = re.result.ad_info.city + console.log('thisposition', this.position); }, fail: (re) => { console.log(re, '失败信息'); } }) - } + }, + fail: () => { + console.log("获取经纬度失败"); + }, }); }, //提示用户开启定位服务 open() { - // uni.authorize({ - // scope: 'scope.userLocation', - // success: function() { - // console.log('授权成功'); - // }, - // fail: function() { - // console.log('授权失败'); - // } - // }) + var that=this + uni.authorize({ + scope: 'scope.userLocation', + success: function() { + console.log('授权成功'); + that.getLocation1() + }, + fail: function() { + console.log('授权失败'); + uni.showModal({ + content: '检测到您没打开获取信息功能权限,是否去设置打开?', + confirmText: "确认", + cancelText: '取消', + success: (res) => { + if (res.confirm) { + uni.openSetting({ + success: (res) => { + console.log(res); + that.getLocation1(); + } + }) + } else { + console.log('取消'); + return false; + } + } + }) + return false; + } + }) // wx.getSetting({ // success: (res) => { // if (res.authSetting['scope.userLocation'] === false) {