vue-amap参考地址:
https://elemefe.github.io/vue-amap/#/zh-cn/introduction/install
ElementUI参考
https://element.eleme.cn/#/zh-CN/component/quickstart
首先安装依赖
npm install vue-amap --save
在项目的main.js下进行全局引入
//高德地图
import VueAMap from "vue-amap";
Vue.use(VueAMap)
VueAMap.initAMapApiLoader({
// 高德的key,可以注册一个高德的开发者账户进行获取,具体看高德官网流程
key: '你的key',
uiVersion: '1.0.11' , // ui库版本,不配置不加载,
// 插件集合'AMap.Geocoder','AMap.Autocomplete','AMap.PlaceSearch', 'AMap.Scale', 'AMap.OverView',
//'AMap.Geolocation','AMap.ToolBar', 'AMap.MapType', 'AMap.PolyEditor', 'AMap.CircleEditor'
plugin: [
'AMap.Geocoder',
'AMap.Autocomplete',
'AMap.PlaceSearch',
'AMap.Scale',
'AMap.OverView',
'AMap.Geolocation',
'AMap.ToolBar',
'AMap.MapType',
'AMap.PolyEditor',
'AMap.CircleEditor'
],
// 高德 sdk 版本,默认为 1.4.4
v: '1.4.4'
});
添加一个组件(vue的文件)比如我的叫gaodeMap.vue
<template>
<el-dialog
title="选择坐标"
:visible.sync="dialogVisible"
:append-to-body="true"
>
<span>
<div class="amap-page-container">
<el-amap-search-box
class="search-box"
:on-search-result="onSearchResult"
:search-option="searchOption"
:center="mapCenter"
></el-amap-search-box>
<el-amap
:vid="'myAmap'"
:zoom="zoom"
:center="mapCenter"
:events="mapEvents"
:plugin="plugin"
>
<el-amap-marker
:position="marker.position"
:visible="marker.visible"
></el-amap