高德地图输入具体地址获取经纬度

 html代码

        <el-col :span="24">
          <el-form-item label="所在地址" prop="address">
            <el-input
              :disabled="!editValidate"
              v-model="form.address"
            ></el-input>
            <el-button
              type="primary"
              icon="el-icon-search"
              size="mini"
              @click="search()"
            >搜索</el-button
            >
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="经度" >
            <el-input readonly v-model="lng"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="纬度" >
            <el-input readonly v-model="lat"></el-input>
          </el-form-item>
        </el-col>
       <!-- 将地图隐藏-->
        <el-col>
          <div id="mapView" style="overflow: fragments">

          </div>
        </el-col>

js代码

     //在打开dialog 的时候创建地图
this.$nextTick(() => {
        this.initMap()
      })

     initMap() {
      this.map = new window.AMap.Map('mapView', {
        resizeEnable: true
      });

    },



//给按钮绑定的搜索事件
search () {
      let that = this;
      window.AMap.plugin('AMap.PlaceSearch', function () {
        var autoOptions = {
          city: '全国',
          map: that.map, 
          pageSize: 1, 
          pageIndex: 1,
          autoFitView: false 
        };
        var placeSearch = new window.AMap.PlaceSearch(autoOptions);
        placeSearch.search(that.form.address, function (status, result) {
          if (status == 'complete') {
            if (result.poiList.pois.length > 0) {
              let lng = result.poiList.pois[0].location.lng;
              let lat = result.poiList.pois[0].location.lat;
              console.log(lng,lat)
              that.$nextTick(() => {
                that.lng=lng
                that.lat=lat
                // that.$set(that.form,'lng',lng)
                // that.$set(that.form,'lat',lat)
              })
            }
          } 
        });
      });
    },

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值