根据经纬度转换为详细数据地址

this.$http
        .get(url, { params: searchUserParam })
        .then((res) => {
          let result = res.body;
          if (result.status === "SUCCEED") {
            this.tableData = [];
            let resData = result.datas;
            var myGeo = new BMap.Geocoder();
            for (let i = 0; i < resData.length; i++) {
                _this.tableData.push({});//初始化数组内容防止this.$set修改数组空指针报错
                let item = resData[i];
                let lon = item.longitude / 1000000;
                let lat = item.latitude / 1000000;
                let point = new BMap.Point(lon, lat)
               
                myGeo.getLocation(point, function (rs) {
                  // console.log(i)
                  if (rs) {
                    //根据当前位置经纬度解析成地址
                    let addComp = rs.addressComponents;
                    let address =
                      addComp.province +
                      addComp.city +
                      addComp.district +
                      addComp.street +
                      addComp.streetNumber;
                    item.address = address;
                    //按位置修改数组内容
                    _this.$set(_this.tableData,i,item);
                  }
                });
            }
            this.totalCount = result.totalCount;
          }
        });

你可能感兴趣的