落日与鲸
2025-02-25 9a918deed10e5f1a2b668043b720b922940a794c
H5/pages/location/location.vue
@@ -42,11 +42,18 @@
            map: null,
            uid: 0,
            keyword: '',
            markers:[],
            locationList: [],
         };
      },
      methods: {
         clearMarkers() {
            // 清除所有标点
            this.markers.forEach((marker) => {
               this.map.removeOverlay(marker);
            });
            this.markers = []; // 清空存储标点的数组
         },
         back() {
            uni.navigateBack()
         },
@@ -105,7 +112,7 @@
         uni.getLocation({
            type: 'wgs84',
            success: (res) => {
               console.log(res, 'res');
               console.log(res, 'resgetLocation');
               this.longitude = res.longitude;
               this.latitude = res.latitude;
               var point = new BMapGL.Point(res.longitude, res.latitude); // 创建点坐标
@@ -113,6 +120,7 @@
               this.map.centerAndZoom(point, 12);
               var marker = new BMapGL.Marker(point);
               this.map.addOverlay(marker);
               this.markers.push(marker);
               var myGeo = new BMapGL.Geocoder();
               // 根据坐标得到地址描述    
               myGeo.getLocation(new BMapGL.Point(res.longitude, res.latitude), (result) => {
@@ -124,6 +132,7 @@
               })
               this.map.addEventListener('click', (e) => {
                  this.clearMarkers()
                  var mercator = this.map.lnglatToMercator(e.latlng.lng, e.latlng.lat);
                  this.latitude = e.latlng.lat
                  this.longitude = e.latlng.lng
@@ -141,6 +150,7 @@
                  })
                  var marker = new BMapGL.Marker(point);
                  this.map.addOverlay(marker);
                    this.markers.push(marker);
               });
            }
         });