|
@@ -15,30 +15,36 @@ Page({
|
|
|
contentpadding: 0, //顶部padding高度
|
|
|
//
|
|
|
active: 0,
|
|
|
+ //地图
|
|
|
+ longitude: 0,
|
|
|
+ latitude: 0,
|
|
|
+ markers: [],
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
* 生命周期函数--监听页面加载
|
|
|
*/
|
|
|
onLoad: function (options) {
|
|
|
- // 计算
|
|
|
- const systemInfo = wx.getSystemInfoSync();
|
|
|
- const statusBarHeight = systemInfo.statusBarHeight || 0;
|
|
|
- const screenHeight = systemInfo.screenHeight || 0;
|
|
|
- const custom = wx.getMenuButtonBoundingClientRect();
|
|
|
- const customHeight = custom.height + 10 + 2 || 0;
|
|
|
- const bottomNavHeight = systemInfo.screenHeight - systemInfo.safeArea.bottom || 0;
|
|
|
-
|
|
|
- const contentpadding = (statusBarHeight + customHeight) * 750 / systemInfo.windowWidth;
|
|
|
- const contentHeight = (screenHeight - bottomNavHeight - statusBarHeight - customHeight) * 750 / systemInfo.windowWidth;
|
|
|
- this.setData({
|
|
|
- statusBarHeight,
|
|
|
- screenHeight,
|
|
|
- customHeight,
|
|
|
- bottomNavHeight,
|
|
|
- contentpadding,
|
|
|
- contentHeight
|
|
|
- });
|
|
|
+ // 计算
|
|
|
+ const systemInfo = wx.getSystemInfoSync();
|
|
|
+ const statusBarHeight = systemInfo.statusBarHeight || 0;
|
|
|
+ const screenHeight = systemInfo.screenHeight || 0;
|
|
|
+ const custom = wx.getMenuButtonBoundingClientRect();
|
|
|
+ const customHeight = custom.height + 10 + 2 || 0;
|
|
|
+ const bottomNavHeight = systemInfo.screenHeight - systemInfo.safeArea.bottom || 0;
|
|
|
+
|
|
|
+ const contentpadding = (statusBarHeight + customHeight) * 750 / systemInfo.windowWidth;
|
|
|
+ const contentHeight = (screenHeight - bottomNavHeight - statusBarHeight - customHeight) * 750 / systemInfo.windowWidth;
|
|
|
+ this.setData({
|
|
|
+ statusBarHeight,
|
|
|
+ screenHeight,
|
|
|
+ customHeight,
|
|
|
+ bottomNavHeight,
|
|
|
+ contentpadding,
|
|
|
+ contentHeight
|
|
|
+ });
|
|
|
+ //地图
|
|
|
+ this.Getlocation()
|
|
|
},
|
|
|
|
|
|
/**
|
|
@@ -88,5 +94,70 @@ Page({
|
|
|
*/
|
|
|
onShareAppMessage: function () {
|
|
|
|
|
|
- }
|
|
|
+ },
|
|
|
+ //获取当前位置信息
|
|
|
+ Getlocation() {
|
|
|
+ // 获取当前位置信息
|
|
|
+ wx.getLocation({
|
|
|
+ type: 'wgs84',
|
|
|
+ success: (res) => {
|
|
|
+ const {
|
|
|
+ latitude,
|
|
|
+ longitude
|
|
|
+ } = res;
|
|
|
+ console.log('获取到的经纬度:', latitude, longitude); // 添加日志
|
|
|
+ //调用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,
|
|
|
+ latitude: latitude, // 保证 latitude 被设置
|
|
|
+ longitude: longitude, // 保证 longitude 被设置
|
|
|
+ markers: [{ // 设置 markers
|
|
|
+ id: 1,
|
|
|
+ latitude: latitude,
|
|
|
+ longitude: longitude,
|
|
|
+ iconPath: 'https://file-cloud.fmode.cn/13WZ0W7u3l/20240724/7ebg0k104325941.png?imageView2/1/w/200/h/200', // 自定义标记图标
|
|
|
+ width: 40,
|
|
|
+ height: 40,
|
|
|
+ callout: {
|
|
|
+ content: address, // 可以显示解析出的地址
|
|
|
+ color: '#ffffff',
|
|
|
+ bgColor: '#7F56B2',
|
|
|
+ padding: 10,
|
|
|
+ borderRadius: 5,
|
|
|
+ display: 'ALWAYS'
|
|
|
+ }
|
|
|
+ }]
|
|
|
+ });
|
|
|
+ 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'
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+ },
|
|
|
})
|