2023年 vue使用腾讯地图搜索、关键字输入提示、地点显示

本文主要是介绍2023年 vue使用腾讯地图搜索、关键字输入提示、地点显示,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

先看结果
请添加图片描述
vue 在public文件下的index.html文件中引入:

  <script src="//map.qq.com/api/js?v=2.exp&key=你自己的key"></script><script src="https://map.qq.com/api/gljs?v=1.exp&libraries=service&key=你自己的key"></script>

弹窗组件:

<template><div><el-dialogtitle="位置信息":visible.sync="dialogVisible"append-to-bodywidth="66%"top="2vh"class="dialogStyle"@close="dialogVisible = false"><div class="content"><div class="left" v-if="showType == 'add'"><div style="display: flex; margin-bottom: 10px"><el-input v-model="input" placeholder="请输入位置关键字"></el-input><el-button type="primary" @click="search">搜索</el-button></div><div class="adressBox" v-if="adressList.length"><divv-for="(item, index) in adressList":key="index"@click="chooseAdress(item, index)"><spanclass="el-icon-location"style="font-size: 16px; color: #409eff; margin-right: 10px"></span><span :class="[item.isChoose === true ? 'check' : '']">{{item.title}}</span></div></div><el-form ref="form" :model="form" label-width="68px"><el-form-item label="定位类型"><el-inputstyle="width: 86%"v-model="form.mapType"placeholder="请输入定位类型"></el-input></el-form-item><el-form-item label="是否常用"><el-switchv-model="form.isItCommonlyUsed"active-color="#13ce66"inactive-color="#ccc"></el-switch></el-form-item></el-form></div><!-- 地图 --><div id="map" style="width: 140%; height: 600px"></div></div><span slot="footer" class="dialog-footer" v-if="showType == 'add'"><el-button @click="dialogVisible = false">取 消</el-button><el-button type="primary" @click="comfig">确 定</el-button></span></el-dialog></div>
</template><script>
export default {data() {return {dialogVisible: false,input: "",adressList: [],showType: "",form: {mapType: "", //地图类型isItCommonlyUsed: false, //是否常用},chooseItem: {},};},methods: {show(data, type) {Object.assign(this.$data, this.$options.data())console.log(data, "data");this.showType = type;this.dialogVisible = true;this.$nextTick(() => {if (this.showType === "detail") {this.reserMap(data.lat, data.lng, 15);} else {if (data.lat && data.lng) {this.form.mapType = data.remark;this.form.isItCommonlyUsed = data.favorites;this.reserMap(data.lat, data.lng, 15);} else {this.reserMap(33.698948, 106.154273, 4);}}});},// 确定comfig() {this.$emit("comfig", this.chooseItem, this.form);this.adressList = [];this.dialogVisible = false;},//当我点击哪一个的时候改变背景色chooseAdress(data, index) {console.log(data, "选择的地址");this.chooseItem = data;// 取消之前选中的地址样式this.adressList.forEach((item, i) => {if (i !== index) {item.isChoose = false;}});// 设置当前选中的地址样式this.adressList[index].isChoose = true;this.$forceUpdate();this.reserMap(data.location.lat, data.location.lng, 15);},//地图显示reserMap(lat, lng, zoom) {const center = new qq.maps.LatLng(lat, lng);const mapContainer = document.getElementById("map");const map = new qq.maps.Map(mapContainer, {center: center,draggable: true,zoom: zoom,});if (zoom === 15) {const marker = new qq.maps.Marker({position: new qq.maps.LatLng(lat, lng),map: map,});}},// 搜索search() {const suggest = new TMap.service.Suggestion({pageSize: 10, // 返回结果每页条目数regionFix: false, // 搜索无结果时是否固定在当前城市servicesk: "", // key});suggest.getSuggestions({keyword: this.input,servicesk: "", // 签名(可在腾讯地图开放平台中拿)}).then((result) => {console.log(result, "搜索");this.adressList = result.data;this.adressList.forEach((item) => {item.isChoose = false;});// console.log(result, "搜索2");});},},
};
</script><style scoped>
.dialogStyle >>> .el-dialog__footer {text-align: center;
}
.dialogStyle >>> .el-dialog__body {padding-top: 10px;
}
.content {display: flex;
}
.left {width: 90%;margin-right: 20px;
}
.adressBox {width: 100%;height: 300px;overflow: auto;border: 1px solid #c5c5c5;border-radius: 6px;margin-bottom: 20px;
}
.adressBox div {font-size: 16px;padding-left: 14px;line-height: 38px;border-bottom: 1px solid #eee;
}
.adressBox div:hover {background: #e1e1e1;cursor: pointer;
}
.check {font-size: 18px;font-weight: 600;color: #409eff;
}
</style>

签名:
在这里插入图片描述
其他相关地图API可参考:腾讯地图api-基本用法总结 官方文档

这篇关于2023年 vue使用腾讯地图搜索、关键字输入提示、地点显示的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/790333

相关文章

Git可视化管理工具(SourceTree)使用操作大全经典

《Git可视化管理工具(SourceTree)使用操作大全经典》本文详细介绍了SourceTree作为Git可视化管理工具的常用操作,包括连接远程仓库、添加SSH密钥、克隆仓库、设置默认项目目录、代码... 目录前言:连接Gitee or github,获取代码:在SourceTree中添加SSH密钥:Cl

Python中模块graphviz使用入门

《Python中模块graphviz使用入门》graphviz是一个用于创建和操作图形的Python库,本文主要介绍了Python中模块graphviz使用入门,具有一定的参考价值,感兴趣的可以了解一... 目录1.安装2. 基本用法2.1 输出图像格式2.2 图像style设置2.3 属性2.4 子图和聚

windows和Linux使用命令行计算文件的MD5值

《windows和Linux使用命令行计算文件的MD5值》在Windows和Linux系统中,您可以使用命令行(终端或命令提示符)来计算文件的MD5值,文章介绍了在Windows和Linux/macO... 目录在Windows上:在linux或MACOS上:总结在Windows上:可以使用certuti

CentOS和Ubuntu系统使用shell脚本创建用户和设置密码

《CentOS和Ubuntu系统使用shell脚本创建用户和设置密码》在Linux系统中,你可以使用useradd命令来创建新用户,使用echo和chpasswd命令来设置密码,本文写了一个shell... 在linux系统中,你可以使用useradd命令来创建新用户,使用echo和chpasswd命令来设

Python使用Matplotlib绘制3D曲面图详解

《Python使用Matplotlib绘制3D曲面图详解》:本文主要介绍Python使用Matplotlib绘制3D曲面图,在Python中,使用Matplotlib库绘制3D曲面图可以通过mpl... 目录准备工作绘制简单的 3D 曲面图绘制 3D 曲面图添加线框和透明度控制图形视角Matplotlib

Pandas中统计汇总可视化函数plot()的使用

《Pandas中统计汇总可视化函数plot()的使用》Pandas提供了许多强大的数据处理和分析功能,其中plot()函数就是其可视化功能的一个重要组成部分,本文主要介绍了Pandas中统计汇总可视化... 目录一、plot()函数简介二、plot()函数的基本用法三、plot()函数的参数详解四、使用pl

电脑显示mfc100u.dll丢失怎么办?系统报错mfc90u.dll丢失5种修复方案

《电脑显示mfc100u.dll丢失怎么办?系统报错mfc90u.dll丢失5种修复方案》最近有不少兄弟反映,电脑突然弹出“mfc100u.dll已加载,但找不到入口点”的错误提示,导致一些程序无法正... 在计算机使用过程中,我们经常会遇到一些错误提示,其中最常见的就是“找不到指定的模块”或“缺少某个DL

使用Python实现IP地址和端口状态检测与监控

《使用Python实现IP地址和端口状态检测与监控》在网络运维和服务器管理中,IP地址和端口的可用性监控是保障业务连续性的基础需求,本文将带你用Python从零打造一个高可用IP监控系统,感兴趣的小伙... 目录概述:为什么需要IP监控系统使用步骤说明1. 环境准备2. 系统部署3. 核心功能配置系统效果展

使用Java将各种数据写入Excel表格的操作示例

《使用Java将各种数据写入Excel表格的操作示例》在数据处理与管理领域,Excel凭借其强大的功能和广泛的应用,成为了数据存储与展示的重要工具,在Java开发过程中,常常需要将不同类型的数据,本文... 目录前言安装免费Java库1. 写入文本、或数值到 Excel单元格2. 写入数组到 Excel表格

redis中使用lua脚本的原理与基本使用详解

《redis中使用lua脚本的原理与基本使用详解》在Redis中使用Lua脚本可以实现原子性操作、减少网络开销以及提高执行效率,下面小编就来和大家详细介绍一下在redis中使用lua脚本的原理... 目录Redis 执行 Lua 脚本的原理基本使用方法使用EVAL命令执行 Lua 脚本使用EVALSHA命令