vue 使用高德地图制作一个搜索,地图选址的组件

效果展示

效果展示

引入高德地图

    <script type="text/javascript" src="https://webapi.amap.com/maps?v=1.4.15&key=你的key去高德申请很快&plugin=AMap.MouseTool,Amap.PlaceSearch,Amap.Geocoder"></script>

子组件,上完整代码

  1. dom中basic-dialog是我们自己封装的弹窗组件,可以改为自己的弹窗组件 如element的el-dialog
  2. 组件的回显通过show方法传入一个对象包含经纬度和地址名称
  3. 需要子组件emit给父组件的对象中包含什么字段可以自己组装通过submit方法传出去
<template>
  <basic-dialog title="选择位置" :visible="visible" width="55%" @close="close" custom-class="sm-padding-dialog">
    <div class="top-search">
      <el-input v-model="searchInput" placeholder="请输入内容" class="search-input"/>
      <el-button type="primary" @click="searchAddress">搜索</el-button>
    </div>
    <div ref="map" class="map"/>
    <div id="panel"/>
    <span slot="footer" class="dialog-footer">
      <el-button @click="close">取 消</el-button>
      <el-button type="primary" @click="submit">确 定</el-button>
    </span>
  </basic-dialog>
</template>

<script>

// var zoom = 16;
export default {
  name: 'MapChoose',
  data() {
    return {
      // dialog
      visible: false,
      modal: {},
      id: '',
      // map
      map: null,
      mouseTool: null,
      polygon: null,
      markers: null,
      pla
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值