Browse Source

sport-start page

邹能昇 4 months ago
parent
commit
808f7d0abd

+ 90 - 19
nova-werun/pages/home/sport/sport-start/index.js

@@ -13,30 +13,36 @@ Page({
         contentHeight: 0, // 可用内容高度
         contentHeight2: 0,
         contentpadding: 0, //顶部padding高度
+        //地图
+        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()
     },
 
     /**
@@ -86,5 +92,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'
+                });
+            }
+        });
+    },
 })

+ 1 - 2
nova-werun/pages/home/sport/sport-start/index.less

@@ -4,7 +4,6 @@
     .map{
         width: 100%;
         height: 600rpx;
-        background-color: aqua;
     }
     .numberbox{
         width: 100%;
@@ -70,7 +69,7 @@
         .pause{
             width: 200rpx;
             height: 200rpx;
-            margin-top: 80rpx;
+            margin-top: 25rpx;
         }
         .btn-text{
             font-size: 30rpx;

+ 1 - 1
nova-werun/pages/home/sport/sport-start/index.wxml

@@ -2,7 +2,7 @@
 <nav type="back" title="跑步或走路" background-color="{{'#87ceeb'}}" front-color="{{'#ffffff'}}"></nav>
 <view class="all" style="height: {{contentHeight}}rpx;">
     <view class="map">
-
+        <map class="map" enable-zoom="ture" enable-scroll="ture" id="map" longitude="{{longitude}}" latitude="{{latitude}}" scale="18" markers="{{markers}}"></map>
     </view>
     <view class="numberbox">
         <view class="distance">

+ 1 - 1
nova-werun/pages/home/sport/sport-start/index.wxss

@@ -1 +1 @@
-.all{width:100vw}.all .map{width:100%;height:600rpx;background-color:aqua}.all .numberbox{width:100%;height:780rpx;display:flex;align-items:center;flex-direction:column}.all .numberbox .distance{display:flex;align-items:flex-end;margin-top:20rpx}.all .numberbox .distance .dis-num{height:132rpx;font-size:100rpx;display:flex;align-items:flex-end}.all .numberbox .distance .dis-text{height:132rpx;font-size:35rpx;display:flex;align-items:flex-end;padding-bottom:18rpx;margin-left:10rpx}.all .numberbox .number{width:100%;height:200rpx;display:flex;justify-content:space-between;margin-top:30rpx}.all .numberbox .number .num{height:100%;width:255rpx;display:flex;flex-direction:column;justify-content:center;align-items:center}.all .numberbox .number .num .num-num{font-size:50rpx;margin-bottom:18rpx}.all .numberbox .number .num .num-text{width:100%;display:flex;justify-content:center;align-items:center;font-size:28rpx}.all .btn{width:350rpx;height:350rpx;display:flex;justify-content:center;align-items:center;flex-direction:column}.all .btn .pause{width:200rpx;height:200rpx;margin-top:80rpx}.all .btn .btn-text{font-size:30rpx;margin-top:20rpx}
+.all{width:100vw}.all .map{width:100%;height:600rpx}.all .numberbox{width:100%;height:780rpx;display:flex;align-items:center;flex-direction:column}.all .numberbox .distance{display:flex;align-items:flex-end;margin-top:20rpx}.all .numberbox .distance .dis-num{height:132rpx;font-size:100rpx;display:flex;align-items:flex-end}.all .numberbox .distance .dis-text{height:132rpx;font-size:35rpx;display:flex;align-items:flex-end;padding-bottom:18rpx;margin-left:10rpx}.all .numberbox .number{width:100%;height:200rpx;display:flex;justify-content:space-between;margin-top:30rpx}.all .numberbox .number .num{height:100%;width:255rpx;display:flex;flex-direction:column;justify-content:center;align-items:center}.all .numberbox .number .num .num-num{font-size:50rpx;margin-bottom:18rpx}.all .numberbox .number .num .num-text{width:100%;display:flex;justify-content:center;align-items:center;font-size:28rpx}.all .btn{width:350rpx;height:350rpx;display:flex;justify-content:center;align-items:center;flex-direction:column}.all .btn .pause{width:200rpx;height:200rpx;margin-top:25rpx}.all .btn .btn-text{font-size:30rpx;margin-top:20rpx}