官网地址
高德使用
效果图
高德地图获取经纬度
需求地址
1 获取高德地图的key
高德开放平台
2 npm安装vue-amap
npm install vue-amap --save
3 main.js引入vue-amap
import AMap from 'vue-amap';
Vue.use(AMap);
AMap.initAMapApiLoader({
key: '你的key值',
plugin: ['AMap.Geolocation']
});
使用
<template>
<div class="amap-page-container">
<!-- -->
<div :style="{ width: '100%', height: '300px' }">
<el-amap vid="amap" :plugin="plugin" class="amap-demo" :center="center">
</el-amap>
</div>
<div class="toolbar">
<span v-if="loaded"> location: lng = {
{
lng }} lat = {
{
lat }} </span>
<span v-else>正在定位</span>
</div>
<div v-on:click="req_post()">查询周边</div>
</div>
</template>
<script>
export default {
data() {
const self = this;
return {
center: [121.59996, 31.197646],
lng: "",
lat: "",
loaded: false,
plugin: [
{
enableHighAccuracy: true,
timeout: 100,
maximumAge: 0,
convert: true,
showButton: true,
buttonPosition: "RB",
showMarker: true,
showCircle: true,
panToLocation: true,
zoomToAccuracy: true,
extensions: "all",
pName: "Geolocation",
events: {
init(o) {
o.getCurrentPosition((status, result) => {
console.log(result);
if (result && result.position) {
self.lng = result.position.lng;
self.lat = result.position.lat;
self.center = [self.lng, self.lat];
self.loaded = true;
self.$nextTick();
}
});
},
},
},
],
};
},
};
</script>
<style>
.amap-demo {
height: 300px;
}
</style>
参考地址
地图覆盖物(图标覆盖物)
需求地址
效果图
参考