落日与鲸
2025-02-24 018225985d7b82ad8b6cd92f1c83e6564563fcfe
H5/pages/location/location.vue
@@ -5,7 +5,7 @@
            <image src="/static/location/back.png" class="w-19 h-35" mode=""></image>
         </view>
      </u-navbar>
      <view class="" id="container" @regionchange="onRegionChange">
      <view class="" id="container">
      </view>
      <view class=" main">
@@ -46,24 +46,22 @@
         };
      },
      methods: {
         back() {
            uni.navigateBack()
         },
         onRegionChange(e) {
            if (e.type === 'end') {
               // 地图移动结束时执行操作
               console.log('地图移动结束,新的中心点经度:', e.longitude, '新的中心点纬度:', e.latitude);
            }
         },
         changeAdr(value, addr) {
            console.log(value, addr, 'asdasdada');
            this.uid = value
            const pages = getCurrentPages()
            let prevPage = pages[pages.length - 2];
            prevPage.location = addr.address
            prevPage.latitude = addr.point.lat
            prevPage.longitude = addr.point.lng
            setTimeout(() => {
               uni.navigateBack()
            }, 500)
            }, 200)
         },
         // 搜索地点
         searchLocation() {
@@ -73,7 +71,7 @@
               method: 'GET',
               data: {
                  query: this.keyword,
                  location: `${30.39},${104.04}`,
                  location: `${this.latitude},${this.longitude }`,
                  radius: 10000, // 搜索半径,单位:米
                  output: 'json',
                  ak: '3mHKIXMArjgIkgADzOlTYp4XssNSNkwr' // 替换为你自己的 AK
@@ -103,7 +101,7 @@
      },
      onReady() {
         this.map = new BMapGL.Map("container"); // 创建地图实例 
         uni.getLocation({
            type: 'wgs84',
            success: (res) => {
@@ -111,7 +109,10 @@
               this.longitude = res.longitude;
               this.latitude = res.latitude;
               var point = new BMapGL.Point(res.longitude, res.latitude); // 创建点坐标
               this.map.enableScrollWheelZoom(true);
               this.map.centerAndZoom(point, 12);
               var marker = new BMapGL.Marker(point);
               this.map.addOverlay(marker);
               var myGeo = new BMapGL.Geocoder();
               // 根据坐标得到地址描述    
               myGeo.getLocation(new BMapGL.Point(res.longitude, res.latitude), (result) => {
@@ -122,8 +123,28 @@
                  })
               })
               this.map.addEventListener('click', (e) => {
                  var mercator = this.map.lnglatToMercator(e.latlng.lng, e.latlng.lat);
                  this.latitude = e.latlng.lat
                  this.longitude = e.latlng.lng
                  var point = new BMapGL.Point(e.latlng.lng, e.latlng.lat);
                  this.map.centerAndZoom(point, 12);
                  var myGeo = new BMapGL.Geocoder();
                  // 根据坐标得到地址描述
                  myGeo.getLocation(new BMapGL.Point(e.latlng.lng, e.latlng.lat), (result) => {
                     console.log(result, 'result');
                     this.locationList = result.surroundingPois.map((item, index) => {
                        item.id = index + 1
                        return item
                     })
                  })
                  var marker = new BMapGL.Marker(point);
                  this.map.addOverlay(marker);
               });
            }
         });
      }
   }
</script>