VUE高德地图实现根据移动覆盖点获得经纬度坐标和详细地址及根据经纬度确定覆盖点

2023-10-27

  1. 经纬度手动定位,输入经纬度,显示详细地址。
 async handleMapPositioning() {
            const result = await this.$api.getProductLocation(this.unionId);
            this.reMap = new AMap.Map('map-container-re-locate', {
                zoom: 13,
                viewMode: '2D',
                center: [this.lngMain, this.latMain],
            });
            this.addReMapMarker(this.lngMain, this.latMain, result.createTime);
            const _this = this;
            AMap.service('AMap.Geocoder', function () { //回调函数
                //实例化Geocoder
                var geocoder = new AMap.Geocoder({
                    city: ''//城市,默认:“全国”
                });
                console.log('dasd', _this);
                var lnglatXY = [_this.lngMain, _this.latMain];//地图上所标点的坐标
                geocoder.getAddress(lnglatXY, function (status, result) {
                    if (status === 'complete' && result.info === 'OK') {
                        const {
                            province,
                            city,
                            district,
                            township,
                            street,
                            streetNumber
                        } = result.regeocode.addressComponent;
                        var address = '';
                        address = province + city + district + township + street + streetNumber;
                        console.log('ashoialjf', result.regeocode.addressComponent);
                        _this.address = address;
                    } else {
                        _this.$message.info('请输入正确的位置信息');
                    }
                    console.log(address);
                });
            });
        },
  1. 根据覆盖点的移动显示当前经纬度
//设置点可以移动
根据移动后的点获取经纬度
addReMapMarker(lng, lat, info) {
            this.reMarker = new AMap.Marker({
                position: [lng, lat],
                offset: new AMap.Pixel(-5, -5),
                cursor: 'move',
                raiseOnDrag: true,
                draggable: true,
                content: '<div class="mk-tips"><img src="/images/map-marker.png" style="width: 14px;height: 14px;"/>' + info + '</div>'
            });
            this.reMarker.on('dragend', e => {
                this.lngMain = e.lnglat.lng;
                this.latMain = e.lnglat.lat;
                console.log('移动的经纬度', this.lngMain, this.latMain);
                this.handleMapPositioning();
            });
            this.reMap.add(this.reMarker);
        },
  1. 动态设置多点自适应显示并显示运动轨迹
addMarkers(lng, lat, info) {
            var markers = [];
            var positions = [[116.405467, 39.907761], [116.415467, 39.917761], [116.425467, 39.907761],
                [116.385467, 39.907761]];
            for (var i = 0, marker; i < positions.length; i++) {
                marker = new AMap.Marker({
                    map: this.maps,
                    position: positions[i],
                    content: '<div class="mk-tips"><img src="/images/map-marker.png" style="width: 14px;height: 14px;"/>' + info + '</div>',
                    offset: new AMap.Pixel(0, -7),
                });
                markers.push(marker);
            }
            this.maps.add(markers);
            //绘制线路
            var polyline = new AMap.Polyline({
                map: this.maps,
                path: positions,
                showDir: true,
                strokeColor: '#28F',
                strokeWeight: 3,
            });
            var passedPolyline = new AMap.Polyline({
                map: this.maps,
                strokeColor: 'red',
                strokeWeight: 3,
                showDir: true,
                strokeOpacity: 0.7
            });
            marker.on('moving', function (e) {
                passedPolyline.setPath(e.passedPath);
            });
            this.maps.setFitView();
            marker.moveAlong(positions, 5000);
        },
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

VUE高德地图实现根据移动覆盖点获得经纬度坐标和详细地址及根据经纬度确定覆盖点 的相关文章

  • javascript开发web计算器实例教程

    计算器的主要作用是进行数字运算 开发一个计算器功能的web实例 有助于更好的掌握js基础的数字运算能力 本实例详细分析一个js计算器的开发步骤 学习本教程时最好先具备一些基础的js知识 计算器包括显示数字区域和按键区域两大部分 先把计算器的

随机推荐