|
@@ -67,7 +67,9 @@ Component({
|
|
|
},
|
|
|
],
|
|
|
target: 0,
|
|
|
- sharList:[],
|
|
|
+ sharList: [],
|
|
|
+
|
|
|
+ address:"",
|
|
|
|
|
|
},
|
|
|
lifetimes: {
|
|
@@ -98,6 +100,7 @@ Component({
|
|
|
console.log('123', contentpadding);
|
|
|
this.gettarget()
|
|
|
this.order()
|
|
|
+ this.Getlocation()
|
|
|
},
|
|
|
},
|
|
|
|
|
@@ -182,5 +185,51 @@ Component({
|
|
|
});
|
|
|
console.log(this.data.sharList);
|
|
|
},
|
|
|
+ //获取当前位置信息
|
|
|
+ Getlocation() {
|
|
|
+ // 获取当前位置信息
|
|
|
+ wx.getLocation({
|
|
|
+ type: 'wgs84',
|
|
|
+ success: (res) => {
|
|
|
+ const {
|
|
|
+ latitude,
|
|
|
+ longitude
|
|
|
+ } = res;
|
|
|
+ //调用api解析地址
|
|
|
+ wx.request({
|
|
|
+ url: 'https://api.map.baidu.com/reverse_geocoding/v3/?ak=sHZTomd7grslfP7sPKB8tRgT49FK9TEu&output=json&coordtype=gcj02&location=' + latitude + ',' + longitude,
|
|
|
+ data: {},
|
|
|
+ header: {
|
|
|
+ 'Content-Type': 'application/json'
|
|
|
+ },
|
|
|
+ success: (ops) => { // 使用箭头函数
|
|
|
+ console.log(ops);
|
|
|
+ const address = ops.data.result.formatted_address;
|
|
|
+ this.setData({
|
|
|
+ address: address,
|
|
|
+ });
|
|
|
+ console.log(this.data.address);
|
|
|
+ },
|
|
|
+ fail: function (resq) {
|
|
|
+ wx.showModal({
|
|
|
+ title: '信息提示',
|
|
|
+ content: '请求失败',
|
|
|
+ showCancel: false,
|
|
|
+ confirmColor: '#f37938'
|
|
|
+ });
|
|
|
+ },
|
|
|
+ complete: function () {}
|
|
|
+ })
|
|
|
+
|
|
|
+ },
|
|
|
+ fail: (err) => {
|
|
|
+ console.error(err);
|
|
|
+ wx.showToast({
|
|
|
+ title: '获取位置失败',
|
|
|
+ icon: 'none'
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+ },
|
|
|
}
|
|
|
})
|