vue中引入高德地图获取坐标

package.json文件引入依赖

 "vue-amap": "^0.5.10",

main.js全局使用

// 引入vue-amap高德地图
import VueAMap from 'vue-amap'
Vue.use(VueAMap)
// 初始化vue-amap
VueAMap.initAMapApiLoader({
  // 高德的key
  key: '请填写申请的key',
  // 插件集合
  // plugin: ['AMap.Autocomplete', 'AMap.PlaceSearch', 'AMap.Scale', 'AMap.OverView', 'AMap.ToolBar', 'AMap.MapType', 'AMap.PolyEditor', 'AMap.CircleEditor'],
  // 高德 sdk 版本,默认为 1.4.4
  v: '1.4.4'
})

使用组件

点击按钮弹出窗口 
 <el-form-item label="坐标:" prop="lng">
            <span style="margin-right:10px;">{{ pointFrom.lng }},{{ pointFrom.lat }}</span>
            <el-button @click="showPickerDialog=true">拾取坐标</el-button>
          </el-form-item>


<!-- 地图 -->
    <el-dialog
      title="坐标拾取"
      width="800px"
      :visible.sync="showPickerDialog"
      :before-close="onPickerClose"
      :close-on-click-modal="false"
    >
      <el-amap vid="location-picker" :center="center" :zoom="15" :events="mapEvents">
        <el-amap-marker :position="location" />
      </el-amap>

      <div slot="footer">
        <el-button @click="onPickerClose">取 消</el-button>
        <el-button type="primary" @click="confirmLocation">确 定</el-button>
      </div>
    </el-dialog>

 data() {
  return {
   showPickerDialog: false,
      immediatelySave: false,
      center: [120.622233, 31.306421],
      location: [120.622233, 31.306421],
  }
 }
 
 methods: {
 // 取消
  onPickerClose() {
      this.showPickerDialog = false
      this.immediatelySave = false
    },
	
	// 确认
	  confirmLocation() {
      if (this.immediatelySave) {
        this.pointFrom.lng = this.location[0]
        this.pointFrom.lat = this.location[1]
        save(this.pointFrom).then(res => {
          this.$message({
            type: 'success',
            message: '保存成功!'
          })
          this.showPickerDialog = false
          this.immediatelySave = false
        })
      } else {
        this.pointFrom.lng = this.location[0]
        this.pointFrom.lat = this.location[1]
        this.showPickerDialog = false
      }
    },
}	
	

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值