fix
pyt
2025-03-03 27b9723292a2095f7e06d0984ccefc15443d054c
fix
1个文件已修改
53 ■■■■ 已修改文件
H5/pages/location/location.vue 53 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
H5/pages/location/location.vue
@@ -74,7 +74,7 @@
                    prevPage.latitude = addr.location.lat
                    prevPage.longitude = addr.location.lng
                }
                prevPage.location = addr.address || addr.name
                prevPage.location = addr.address || addr.name || addr.title
                setTimeout(() => {
                    uni.navigateBack()
                }, 200)
@@ -135,21 +135,31 @@
        },
        onReady() {
            this.map = new BMapGL.Map("container"); // 创建地图实例 
            const that = this
            // uni.getLocation({
            //     type: 'wgs84',
            //     success: (res) => {
            navigator.geolocation.getCurrentPosition(success, error, options);
            function success(position) {
                let that = this
                const latitude = position.coords.latitude;
                const longitude = position.coords.longitude;
                const accuracy = position.coords.accuracy; // 精度,单位米
                that.latitude = latitude
                that.latitude = latitude
                //  在这里可以使用获取到的经纬度信息,例如在地图上显示位置等。
                var point = new BMapGL.Point(longitude, latitude); // 创建点坐标
                that.map.enableScrollWheelZoom(true);
                that.map.centerAndZoom(point, 12);
                var marker = new BMapGL.Marker(point);
                that.map.addOverlay(marker);
                that.markers.push(marker);
                var myGeo = new BMapGL.Geocoder();
                // 根据坐标得到地址描述
                myGeo.getLocation(new BMapGL.Point(longitude, latitude), (result) => {
                    that.locationList = result.surroundingPois.map((item, index) => {
                        item.id = index + 1
                        return item
                    })
                })
            }
            function error(err) {
@@ -174,27 +184,6 @@
                timeout: 5000, // 5 秒超时
                maximumAge: 0 //  不使用缓存
            };
            // let res = {
            //     longitude: 101.725544,
            //     latitude: 26.587259
            // }
            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);
            this.markers.push(marker);
            var myGeo = new BMapGL.Geocoder();
            // 根据坐标得到地址描述
            myGeo.getLocation(new BMapGL.Point(res.longitude, res.latitude), (result) => {
                this.locationList = result.surroundingPois.map((item, index) => {
                    item.id = index + 1
                    return item
                })
            })
            this.map.addEventListener('click', (e) => {
                this.clearMarkers()
                var mercator = this.map.lnglatToMercator(e.latlng.lng, e.latlng.lat);
@@ -205,11 +194,19 @@
                var myGeo = new BMapGL.Geocoder();
                // 根据坐标得到地址描述    
                myGeo.getLocation(new BMapGL.Point(e.latlng.lng, e.latlng.lat), (result) => {
                    console.log(result,'result');
                    if( result.surroundingPois.length>0){
                    this.locationList = result.surroundingPois.map((item, index) => {
                        item.id = index + 1
                        return item
                    })
                    }else{
                        this.locationList =[{
                            id:1,
                            title:result.address,
                            point:{lat:e.latlng.lat,lng:e.latlng.lng}
                        }]
                    }
                })
                var marker = new BMapGL.Marker(point);