邓洁 : 区域下拉框数据获取及完善定位功能

This commit is contained in:
dengj
2023-11-15 15:49:30 +08:00
parent dd05376541
commit d9d7cb36de
9 changed files with 203 additions and 174 deletions

View File

@@ -18,7 +18,6 @@
</template>
<script>
import QQMapWX from "@/utils/qqmap-wx-jssdk.min.js"
export default {
name: "inputAndSwiper",
props: {
@@ -39,7 +38,7 @@
},
data() {
return {
position: ''
position: uni.getStorageSync('city')+uni.getStorageSync('district').slice(0, 2)
};
},
options: {
@@ -47,92 +46,11 @@
},
created() {
if (this.type !== '0') {
this.open()
// this.open()
}
},
methods: {
getUserLocation() {
var that = this
let qqmapsdk = new QQMapWX({
key: 'ZRKBZ-Q7FWL-GVZPK-MCRBU-4XFB5-ATBDB'
});
uni.getFuzzyLocation({
type: 'wgs84',
success(res) {
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("解析地址成功", re);
console.log(re.result.ad_info.city);
console.log(re.result.ad_info.district);
let city = re.result.ad_info.city
let district = re.result.ad_info.district
that.position = city.slice(0, 2) + district.slice(0, 2)
},
fail: (re) => {
console.log(re, '失败信息');
}
})
},
fail(err) {
console.log("获取经纬度失败", err);
},
});
},
//提示用户开启定位服务
open() {
var that = this
uni.authorize({
scope: 'scope.userFuzzyLocation',
success: function() {
console.log('授权成功');
that.getUserLocation()
},
fail: function() {
console.log('授权失败');
uni.showModal({
content: '检测到您没打开获取信息功能权限,是否去设置打开?',
confirmText: "确认",
cancelText: '取消',
success: (res) => {
if (res.confirm) {
uni.openSetting({
success: (res) => {
console.log(res);
that.getUserLocation();
}
})
} else {
console.log('取消');
return false;
}
}
})
return false;
}
})
// wx.getSetting({
// success: (res) => {
// if (res.authSetting['scope.userLocation'] === false) {
// wx.showModal({
// title: '提示',
// content: '请打开定位服务后重新进入该页面',
// confirmText: '去设置',
// success: (res) => {
// if (res.confirm) {
// wx.openSetting()
// }
// }
// })
// }
// }
// })
}
}
}
</script>