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

uniapp 展示地图,并获取当前位置信息(精确位置)

使用uniapp 提供的map标签 

	  <map :key='mapIndex'  class="container" :latitude="latitude" :longitude="longitude"  ></map>

页面初始化的时候,获取当前的位置信息

		created() {let that = thisuni.getLocation({type: 'gcj02',// 火星坐标系isHighAccuracy:true,geocode:true,success: function (res) {that.latitude = res.latitudethat.longitude  = res.longitude// 通过经纬度获取位置信息that.locationName(res.latitude, res.longitude)},fail:function(res){console.log()uni.showToast({title: '获取位置信息失败',duration: 2000,icon:'error'});}});},

根据获取到的经纬度 获取 位置信息(此处使用的是 高德地图的位置服务,通过高德地图的逆地理位置解析,获取定位到的经纬度的 位置信息)

			// 定义解析位置信息的方法locationName(latitude, longitude) {let that = thislet mapKey = '1d8xxxxxxxxxxxxxxxx'; // 构造URLvar url = 'https://restapi.amap.com/v3/geocode/regeo?key=' + mapKey + '&location=' + longitude + ',' + latitude;// 使用fetch发送请求fetch(url).then(response =>  response.json()).then(data => {if (data.status === '1') {// 获取到的地址信息var address = data.regeocode.formatted_address;that.nowAddressInfo = address} else {console.error('Error: ' + data.info);}}).catch(error => console.error('Error:', error));},

高德地图获取key

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

相关文章:

  • Autosar实践——诊断配置(DaVinci Configuration)
  • 植物大战僵尸杂交版全新版v2.1解决全屏问题
  • 【code-server】Code-Server 安装部署
  • 博客摘录「 YOLOv5模型剪枝压缩」2024年5月11日
  • HttpSecurity
  • Mysql union语句
  • MySQL之高级特性(四)
  • roles安装wordpress
  • 【Python高级编程】饼状图中autopct和startangle用来做什么的
  • 【ARM Coresight Debug 系列 -- ARMv8/v9 Watchpoint 软件实现地址监控详细介绍】
  • jvm工具-jps、jstat、jmap、jstack
  • LVS负载均衡群集+NAT部署
  • 使用 Oracle SQL Developer 导入数据
  • 品质主管的面试题目
  • 算法专题总结链接地址
  • Oracle--存储结构
  • 【计算机毕业设计】259基于微信小程序的医院综合服务平台
  • HP惠普暗影精灵10 OMEN Gaming Laptop 16-wf1xxx原厂Win11系统镜像下载
  • [Day 9] 區塊鏈與人工智能的聯動應用:理論、技術與實踐
  • van-list 遇到的问题
  • DockerCompose+Jenkins+Pipeline流水线打包Vue项目(解压安装配置Node)入门
  • 【新课程】PICO VR 交互开发指南
  • 天童美语:为了得体退出的那一天,你一定要好好爱孩子
  • 什么是JWT?为什么用JWT?JWT的实战案例
  • SpringBoot+Vue小区物业管理系统 附带详细运行指导视频
  • 在不使用js在情况下只用css实现瀑布流效果
  • AMS(ActivityManagerService)源码解析2,Android应用是如何被启动的
  • 数据库事务隔离级别
  • Pytest 记录日志输出到控制台和写入文件
  • LINUX网络FTP服务