博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Vue中安装高得地图AmapVue 组件,根据坐标获取位置名称
阅读量:4186 次
发布时间:2019-05-26

本文共 1593 字,大约阅读时间需要 5 分钟。

后端人员还要写前端,真是头大。第一次在vue中使用高德地图提供的组件记录一下。

安装使用看官方文档就够了:https://jimnox.gitee.io/amap-vue/intro/installation.html

1、 引入依赖

npm install --save @amap/amap-vue

2、全局配置

import AmapVue from '@amap/amap-vue';AmapVue.config.version = '2.0'; // 默认2.0,这里可以不修改AmapVue.config.key = '您的JSAPI KEY';AmapVue.config.plugins = [  'AMap.ToolBar',  'AMap.MoveAnimation',  // 在此配置你需要预加载的插件,如果不配置,在使用到的时候会自动异步加载];Vue.use(AmapVue);

说明:

  • key使用你自己申请的key。
  • 添加一些地图类的插件, 在vue项目中可以直接 通过new AMap.ToolBar()使用。

配置到这一步就完成了

下面是根据经纬度获取位置的代码:

getPositionByLonLats() {                const that = this;                // 需要在插件中引入                let geocoder = new AMap.Geocoder({});                // 第一个参数是你的经纬度数据                geocoder.getAddress(this.position, function (status, result) {                    if (status === 'complete' && result.info === 'OK') {                        // console.log(result.regeocode.formattedAddress);                        that.address = result.regeocode.formattedAddress;                        console.log(that.address);                    } else {                        that.address = "未检测到该地址"                    }                });            },

在插件中引入 AMap.Geocoder

AmapVue.config.plugins = [  'AMap.ToolBar',  'AMap.MoveAnimation',  'AMap.Geocoder'  // 在此配置你需要预加载的插件,如果不配置,在使用到的时候会自动异步加载];

遇见的问题:

vue中更新 地图的经纬度数据时,地图的坐标点居然不更新。使用this.$forceUpdate() 也不起作用。

将下面的代码

this.position[0]= Number(this.currentViewData.longiatude)this.position[1]= Number(this.currentViewData.latitude)

改成这样,就生效了。

this.position= [Number(this.currentViewData.longiatude),Number(this.currentViewData.latitude)]

amazing…

转载地址:http://fdfoi.baihongyu.com/

你可能感兴趣的文章
在eclipse中通过local的模式可以正确的调试hadoop2.2
查看>>
HDFS 常用的文件操作命令
查看>>
使用Hive如何和Hbase集成
查看>>
把eclipse中的hadoop项目,换了一个工作空间,再次启动任务时
查看>>
在Win上提交hadoop集群的作业
查看>>
JAVA IDE IntelliJ IDEA使用简介(一)—之界面元素
查看>>
GROUP BY与COUNT用法详解
查看>>
pgadmin
查看>>
Greenplum性能调优
查看>>
gp性能管理
查看>>
linux的清屏命令
查看>>
maven打jar包
查看>>
Win10系统ie浏览器打不开网页的2种解决方法
查看>>
自己搭建一套hadoop的运行环境
查看>>
本次装的hadoop版本是hadoop1.2的版本
查看>>
跳板机SecureCRT
查看>>
namenode的log时,散仙发现有如下的警告信息
查看>>
用过eclipse直接向hadoop提交MR作业
查看>>
在执行bin/hadoop checknative 命令时
查看>>
MapReduce作业
查看>>