Merge pull request '邓洁:位置定位' (#29) from dengjie into master

Reviewed-on: http://git.feashow.cn/odjbin/city-store-transfer/pulls/29
This commit is contained in:
odjbin
2023-11-08 01:39:47 +00:00

View File

@@ -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) {