美文网首页
uniapp使用map组件动态添加marker(nvue)

uniapp使用map组件动态添加marker(nvue)

作者: 子夜照弦歌 | 来源:发表于2021-07-09 15:35 被阅读0次

    代码如下:

    注:不要使用push的方式

    let _this = this;
    
                this.timer = setInterval(() => {
                    console.log('3秒执行一次定位');
    
                    uni.getLocation({
                        type: 'wgs84',
                        success: function(res) {
                            // console.log('当前位置的经度:' + res.longitude);
                            // console.log('当前位置的纬度:' + res.latitude);
                            let { longitude, latitude } = res;
                            let lnglat = JSON.stringify({
                                lng: longitude,
                                lat: latitude
                            });
                            console.log(lnglat);
                            _this.location = {
                                longitude: longitude,
                                latitude: latitude
                            };
                            let m = {
                                id: _this.markers.length,
                                latitude: latitude,
                                longitude: longitude,
                                title: '',
                                zIndex: '1',
                                rotate: 0,
                                width: 20,
                                height: 20,
                                anchor: {
                                    x: 0.5,
                                    y: 1
                                }
                            };
    
                            _this.markers = _this.markers.concat([m]);
                            _this.point.push({
                                longitude: longitude,
                                latitude: latitude
                            });
                        },
                        fail: function(err) {
                            console.log(err);
                        }
                    });
                }, 3000);
            
    

    相关文章

      网友评论

          本文标题:uniapp使用map组件动态添加marker(nvue)

          本文链接:https://www.haomeiwen.com/subject/dfpfpltx.html