vue pc端使用腾讯地图进行搜索和选点

组件内容为:

<template>
  <a-modal v-model="visibleMap" title="选择地点" @cancel="handleCancelMap" width="80%">
    <iframe width="100%" style="height: 60vh; width: 76vw; border: none;" :src="map_src"></iframe>
    <template slot="footer">
      <a-button @click="handleSureMap" type='primary'>确定</a-button>
      <a-button @click="handleCancelMap" type='primary'>取消</a-button>
    </template>
  </a-modal>
</template>

<script>
  export default {
    name: 'mapComponents',
    props: {
      visibleMap: {
        type: Boolean,
        default: false,
      }
    },
    data() {
      return {
        map_src: 'https://mapapi.qq.com/web/mapComponents/locationPicker/v/index.html?search=1&type=1&key=这里放你使用的key&referer=location',
        form: {
          //省市区ID
          id_area: [
            0,
            0,
            0
          ],
          address: '',
          lng: '',
          lat: '',
        },
        map_data: {
          url: 'https://mapapi.qq.com/web/mapComponents/locationPicker/v/index.html?search=1&type=1&key=这里放你使用的key&referer=location',
          address: '',
          lng: '',
          lat: '',
        },
      }
    },
    created() {
      let that = this
      window.addEventListener('message', function(event) {
        // 接收位置信息,用户选择确认位置点后选点组件会触发该事件,回传用户的位置信息
        var loc = event.data;
        console.log(loc)
        if (loc && loc.module == 'locationPicker') { //防止其他应用也会向该页面post信息,需判断module是否为'locationPicker'
          that.map_data.address = loc.poiaddress
          that.map_data.lat = loc.latlng.lat
          that.map_data.lng = loc.latlng.lng
          that.$emit('chooseMapPoint',that.map_data)
        } else {
          that.$emit('chooseMapPoint','选择数据为空')
        }
      }, false);
    },
    methods: {
      //地图选点确定
      handleSureMap() {
        this.$emit('sure', this.map_data)
      },
      // 取消
      handleCancelMap () {
        this.$emit('cancel')
      },
    }
  }
</script>

<style>
</style>

使用:

<MapComponent :visibleMap='visibleMap' @chooseMapPoint='getCallMap' @cancel='cancelMap' @sure='sureMap'></MapComponent>
methods:{
	getCallMap (e) {
        console.log(e)
      },
      cancelMap () {
        this.visibleMap = false
      },
      sureMap(e){
        console.log(e)
      },
}

(腾讯地图文档上的那个链接太离谱了,用这个https://mapapi.qq.com/web/mapComponents/locationPicker/v/index.html?search=1&type=1&key=这里放你使用的key&referer=location就行)

  • 5
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值