关于javascript:根据经纬度转换为详细数据地址

40次阅读

共计 685 个字符,预计需要花费 2 分钟才能阅读完成。

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;
          }
        });

正文完
 0