|
|
@@ -174,26 +174,32 @@
|
|
|
async inputBut() {
|
|
|
let that = this;
|
|
|
try {
|
|
|
- // 先检查权限
|
|
|
- const authSetting = await this.checkLocationAuth();
|
|
|
- if (!authSetting) {
|
|
|
- await this.showAuthorizeGuide();
|
|
|
- return;
|
|
|
- }
|
|
|
// 选择位置
|
|
|
- const res = await this.chooseLocation();
|
|
|
- console.log('位置名称:' + res.name);
|
|
|
- console.log('详细地址:' + res.address);
|
|
|
- console.log('纬度:' + res.latitude);
|
|
|
- console.log('经度:' + res.longitude);
|
|
|
- // 更新数据
|
|
|
- that.propertyData.lng = res.longitude;
|
|
|
- that.propertyData.lat = res.latitude;
|
|
|
- that.propertyData.address = res.address;
|
|
|
- that.propertyData.complexName = res.name || '';
|
|
|
- // 根据地址信息设置区域
|
|
|
- this.setDistrictByAddress(res.address);
|
|
|
-
|
|
|
+ uni.chooseLocation({
|
|
|
+ success: function(res) {
|
|
|
+ // 更新数据
|
|
|
+ that.propertyData.lng = res.longitude;
|
|
|
+ that.propertyData.lat = res.latitude;
|
|
|
+ that.propertyData.address = res.address;
|
|
|
+ that.propertyData.complexName = res.name || '';
|
|
|
+ // 根据地址信息设置区域
|
|
|
+ that.setDistrictByAddress(res.address);
|
|
|
+ console.log('当前位置的经度:' + res.longitude);
|
|
|
+ console.log('当前位置的纬度:' + res.latitude);
|
|
|
+ },
|
|
|
+ fail: async function(err) {
|
|
|
+ console.log('获取位置失败:', err);
|
|
|
+ // 如果是授权被拒绝
|
|
|
+ if (err.errMsg.indexOf('auth deny') !== -1) {
|
|
|
+ try {
|
|
|
+ // 引导用户手动开启授权
|
|
|
+ await showAuthorizeGuide();
|
|
|
+ } catch (e) {
|
|
|
+ console.log('授权引导失败:', e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
} catch (err) {
|
|
|
console.log('获取位置失败:', err);
|
|
|
if (err.errMsg && (err.errMsg.includes('auth deny') || err.errMsg.includes('fail cancel'))) {
|
|
|
@@ -219,14 +225,14 @@
|
|
|
});
|
|
|
},
|
|
|
// 选择位置
|
|
|
- chooseLocation() {
|
|
|
- return new Promise((resolve, reject) => {
|
|
|
- uni.chooseLocation({
|
|
|
- success: resolve,
|
|
|
- fail: reject
|
|
|
- });
|
|
|
- });
|
|
|
- },
|
|
|
+ // chooseLocation() {
|
|
|
+ // return new Promise((resolve, reject) => {
|
|
|
+ // uni.chooseLocation({
|
|
|
+ // success: resolve,
|
|
|
+ // fail: reject
|
|
|
+ // });
|
|
|
+ // });
|
|
|
+ // },
|
|
|
showAuthorizeGuide() {
|
|
|
return new Promise((resolve, reject) => {
|
|
|
uni.showModal({
|