当前位置: 首页 > news >正文

vue集成高德地图API实现坐标拾取功能

安装与配置:

组件 | vue-amapDescriptionicon-default.png?t=O83Ahttps://elemefe.github.io/vue-amap/#/zh-cn/introduction/install简介 | @vuemap/vue-amap简介icon-default.png?t=O83Ahttps://vue-amap.guyixi.cn/zh-cn/introduction/introduction.html        ​​​​我的应用 | 高德控制台高德开放平台官网控制台提供了高德开发者Key管理,Key可视化分析等功能。icon-default.png?t=O83Ahttps://console.amap.com/dev/key/app        

页面设计与引用

<template><div class="amap-wrapper"><el-amap class="amap-box"  :vid="'amap-vue'"  :bubble="true" :center="center" :zoom="zoom" :events="events"><!-- 搜索框 --><el-amap-search-boxclass="searchBox":search-option="searchOption":on-search-result="onSearchResult"/><!-- 标注点 --><el-amap-marker :position="center" ></el-amap-marker><!-- tootip --><el-amap-text:position="mark":text="mark.toString()":offset="[100,-20]"></el-amap-text><!-- 信息窗体--><el-amap-info-window:position="center":offset="[0,-30]"><div style="margin: 15px 5px 0">{{ centerAddress.formattedAddress }}</div></el-amap-info-window></el-amap></div>
</template>
<script>export default {name: 'siteinfo',data() {return {zoom: 10,//初始缩放比例center: [104.077448,30.624161],//初始中心点mark: [104.077448,30.624161],//初始标记点centerAddress: {//中心点位置信息city: "全国",district: "全国",province: "全国",township: "",formattedAddress: "全国",},markAddress: {//标记点位置信息city: "全国",district: "全国",province: "全国",township: "",formattedAddress: "全国",},searchOption:{city:"全国",citylimit:true,},events: {// init: (e) => {//     // this.center=[101.722732,26.580607]//     this.getAddress(this.center);// },click: (e) => {this.center = [e.lnglat.lng, e.lnglat.lat]this.getAddress(this.center);},mousemove: (e) => {this.mark = [e.lnglat.lng, e.lnglat.lat]}}}},methods: {// 使用AMap服务获取地址getAddress(latLong){var geocoder;AMap.plugin("AMap.Geocoder",function(){geocoder = new AMap.Geocoder({radius: 1000,extensions: 'all'});})geocoder.getAddress(latLong, (status, result) => {console.log("address", result)if (status === 'complete' && result.info === 'OK') {// 获取当前点名称const address = result.regeocode.formattedAddress;this.centerAddress = {city: result.regeocode.addressComponent.city,district: result.regeocode.addressComponent.district,province: result.regeocode.addressComponent.province,township: result.regeocode.addressComponent.township,formattedAddress: address,}// console.log("address", result)}});},// 地图搜索回调onSearchResult(pois) {if( pois.length !== 0){this.center=[pois[0].lng, pois[0].lat];this.getAddress(this.center);}console.log("地图回调", pois);},//修改时将当前坐标赋值rowEdit(row, index){console.log("row",row)this.center=row.latLong.split(',').map(Number)this.getAddress(this.center);this.$refs.crud.rowEdit(row,index)},//新增时给个初始位置rowAdd(){this.center=[104.077448,30.624161];this.getAddress(this.center);},// 更新handleUpdate: function (row, index, done,loading) {row.province = this.centerAddress.provincerow.city = this.centerAddress.cityrow.disrict = this.centerAddress.districtrow.addressDetail = this.centerAddress.formattedAddressrow.latLong = this.center.toString()console.log(row)if( row.latLong ){putObj(row).then(data => {this.$message.success('修改成功')done()this.searchForm = {}this.getList(this.page)}).catch(() => {loading();});}else {this.$message.error('请选择筛查地点')}},// 保存handleSave: function (row, done,loading) {row.province = this.centerAddress.provincerow.city = this.centerAddress.cityrow.disrict = this.centerAddress.districtrow.addressDetail = this.centerAddress.formattedAddressrow.latLong = this.center.toString()console.log(row)addObj(row).then(data => {this.$message.success('添加成功')done()this.searchForm = {}this.getList(this.page)}).catch(() => {loading();});},}}
</script><style scoped>
.amap-wrapper {width: 100%;height: 75Vh;position: relative;.searchBox{position: absolute;top: 20px;left: 20px;}
}
</style>

http://www.lryc.cn/news/522283.html

相关文章:

  • Spring Boot Actuator 详细介绍
  • 联通用户管理系统(一)
  • go chan底层分析
  • idea上git log面板的使用
  • WOA-Transformer鲸鱼算法优化编码器时间序列预测(Matlab实现)
  • dock 制作 python环境
  • 2025第3周 | json-server的基本使用
  • Autodl转发端口,在本地机器上运行Autodl服务器中的ipynb文件
  • flutter Get GetMiddleware 中间件不起作用问题
  • RabbitMQ(三)
  • 【Python】Python之locust压测教程+从0到1demo:基础轻量级压测实战(1)
  • 【JavaScript】基础内容,HTML如何引用JavaScript, JS 常用的数据类型
  • vue使用自动化导入api插件unplugin-auto-import,避免频繁手动导入
  • 在 C# 中的Lambda 表达式
  • 奉加微PHY6230兼容性:部分手机不兼容
  • 32单片机综合应用案例——基于GPS的车辆追踪器(三)(内附详细代码讲解!!!)
  • 45_Lua模块与包
  • 深度学习电影推荐-CNN算法
  • 【Git 】探索 Git 的魔法——git am 与补丁文件的故事
  • G1原理—5.G1垃圾回收过程之Mixed GC
  • 机器人传动力系统介绍
  • 1161 Merging Linked Lists (25)
  • 内联变量(inline variables):在多个文件中共享全局常量
  • Jmeter进行http接口并发测试
  • 力扣解题汇总_JAVA
  • ubuntu下安装编译cmake,grpc与protobuf
  • SQL Prompt 插件
  • 知识图谱抽取分析中,如何做好实体对齐?
  • 【Python通过UDP协议传输视频数据】(界面识别)
  • 【伪随机数】关于排序算法自测如何生成随机数而引发的……