邓洁 : 区域下拉框数据获取及完善定位功能
This commit is contained in:
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user