记录在vue项目中使用高德地图js API的过程
首先注册账号申请key
项目中引入api
- 在开发文档中的“准备”目录中复制api,引入vue项目的index.html中,替换key
- 项目主要使用的是定位服务,在菜单中找到定位的api写到项目App.vue中,让页面一加载就获取定位信息、
<template>
<div id="app">
<router-view/>
</div>
</template>
<script>
export default {
name: 'app',
created() {
this.getLocation()
},
methods: {
getLocation() {
AMap.plugin('AMap.Geolocation', function () {
var geolocation = new AMap.Geolocation({
// 是否使用高精度定位,默认:true
enableHighAccuracy: true,
// 设置定位超时时间,默认:无穷大
timeout: 10