Browse Source

mingsu page

邹能昇 4 months ago
parent
commit
e1b70df689

+ 22 - 0
nova-tourism/components/homestay/index.js

@@ -278,5 +278,27 @@ Component({
                 }
             }
         },
+        //添加后台经纬度
+        //  async setadd() {
+        //     let ShopStore = new Parse.Query('ShopStore');
+        //     ShopStore.equalTo('company', company);
+        //     ShopStore.equalTo('objectId', "GyeSIi3zwL");
+        
+        //     let store = await ShopStore.first();
+            
+        //     // 创建 GeoPoint 对象
+        //     let location = new Parse.GeoPoint(28.679224,117.818856); // 注意:GeoPoint 的参数是 (latitude, longitude)
+            
+        //     // 设置 location 字段
+        //     store.set('location', location);
+            
+        //     try {
+        //         let saveDate = await store.save();
+        //         console.log(saveDate);
+        //         console.log("上传地址成功");
+        //     } catch (error) {
+        //         console.error("保存数据时出现错误:", error);
+        //     }
+        // }
     }
 });

+ 65 - 3
nova-tourism/pages/homestay/homestay-detail/index.js

@@ -23,7 +23,12 @@ Page({
         daysBetween: 0,
         istoday: null,
         storeList: [],
-        roomList: []
+        roomList: [],
+
+        //地图
+        longitude: 0,
+        latitude: 0,
+        markers: [],
     },
 
     /**
@@ -79,12 +84,13 @@ Page({
         this.gethomestay()
         this.getroom()
         this.getpic()
+
     },
 
     /**
      * 生命周期函数--监听页面初次渲染完成
      */
-    onReady: function () {
+    onReady: function() {
 
     },
 
@@ -143,6 +149,7 @@ Page({
         ShopStore.equalTo('type', "stay");
         ShopStore.equalTo('objectId', this.data.objectId);
         ShopStore.notEqualTo('isDeleted', "true");
+        ShopStore.include('location');
 
         let store = await ShopStore.find();
         let storeListPromises = store.map(async item => {
@@ -156,7 +163,7 @@ Page({
         this.setData({
             storeList
         });
-
+        this.Getlocation()
         console.log(this.data.storeList);
     },
     //获取房间信息
@@ -223,4 +230,59 @@ Page({
 
         console.log(this.data.imageUrls); // 输出 imageUrls
     },
+    //获取当前位置信息
+    Getlocation() {
+        // 假设 this.storeList[0].location 是一个 Parse.GeoPoint 对象
+        const storeLocation = this.data.storeList[0].location;
+
+        // 从 GeoPoint 对象中获取经纬度
+        const latitude = storeLocation.latitude; // 纬度
+        const longitude = storeLocation.longitude; // 经度
+
+        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: 30,
+                        height: 30,
+                        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 () {}
+        });
+    },
 })

+ 7 - 0
nova-tourism/pages/homestay/homestay-detail/index.json

@@ -2,5 +2,12 @@
   "usingComponents": {
     "van-sticky": "@vant/weapp/sticky/index",
     "van-icon": "@vant/weapp/icon/index"
+  },
+  "permission": {
+    "scope": {
+      "location": {
+        "desc": "您的位置信息将用于展示地图"
+      }
+    }
   }
 }

+ 2 - 3
nova-tourism/pages/homestay/homestay-detail/index.less

@@ -72,13 +72,12 @@
             }
             .info-map{
                 width: 100%;
-                height: 250rpx;
                 display: flex;
                 align-items: center;
+                margin-top: 20rpx;
                 .map{
                     width: 480rpx;
-                    height: 188rpx;
-                    background-color: aqua;
+                    height: 270rpx;
                 }
                 .info-call{
                     width: 156rpx;

+ 3 - 1
nova-tourism/pages/homestay/homestay-detail/index.wxml

@@ -22,7 +22,9 @@
             </view>
             <view class="info-intr">{{storeList[0].desc}}</view>
             <view class="info-map">
-                <view class="map"></view>
+                <view class="map">
+                    <map class="map" enable-zoom="ture" enable-scroll="ture" id="map" longitude="{{longitude}}" latitude="{{latitude}}" scale="20" markers="{{markers}}"></map>
+                </view>
                 <view class="info-call">
                     <image src="https://file-cloud.fmode.cn/EbxZUK5lBI/20241122/n7me1o092906284.png"></image>
                     <view class="call-tex">联系望仙管家</view>

File diff suppressed because it is too large
+ 0 - 0
nova-tourism/pages/homestay/homestay-detail/index.wxss


+ 1 - 1
project.config.json

@@ -10,7 +10,7 @@
         "include": []
     },
     "setting": {
-        "urlCheck": true,
+        "urlCheck": false,
         "es6": true,
         "enhance": true,
         "postcss": true,

Some files were not shown because too many files changed in this diff