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

  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);
        },
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值