微信小程序怎么通过API获取当前位置的经纬度
发表于:2024-10-22 作者:千家信息网编辑
千家信息网最后更新 2024年10月22日,本篇内容介绍了"微信小程序怎么通过API获取当前位置的经纬度"的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有
千家信息网最后更新 2024年10月22日微信小程序怎么通过API获取当前位置的经纬度
本篇内容介绍了"微信小程序怎么通过API获取当前位置的经纬度"的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!
效果图:
1、wxml文件
2、 js文件
var coors;Page({ data: { polyline: [], markers: [], }, onReady: function() { this.mapContext = wx.createMapContext("map", this); }, onLoad: function(options) { // 获取当前地图,设置经纬度,传递过来的坐标,用户下单的坐标地址。 console.log(options); wx.getLocation({ success: (res) => { this.setData({ latitude: options.latitude, longitude: options.longitude }); this.getCenterLocation(res); wx.request({ url: 'https://apis.map.qq.com/ws/direction/v1/driving/?from=' + this.data.markers[0].latitude + ',' + this.data.markers[0].longitude + '&to=' + this.data.markers[1].latitude + ',' + this.data.markers[1].longitude + '&output=json&callback=cb&key=PD5BZ-K2VRO-CPEWZ-SOBAC-4KCDT-KAFLF', success: (res) => { coors = res.data.result.routes[0].polyline for (var i = 2; i < coors.length; i++) { coors[i] = coors[i - 2] + coors[i] / 1000000 } console.log(coors) //划线 var b = []; for (var i = 0; i < coors.length; i = i + 2) { b[i / 2] = { latitude: coors[i], longitude: coors[i + 1] }; console.log(b[i / 2]) } this.setData({ polyline: [{ points: b, color: "#00ae20", width: 4, dottedLine: false }], }) } }) } }); }, // 两个坐标 一个下单地址,一个工程师接单地址,然后不停的更新工程师的坐标位置。 getCenterLocation: function(res) { this.setData({ markers: [{ iconPath: "/resources/center.png", id: 0, latitude: res.latitude, longitude: res.longitude, width: 30, height: 30, alpha: 0.8, callout: { content: " 我的位置 ", color: "#ffffff", fontSize: 10, borderRadius: 10, bgColor: "#6e707c", padding: 5, display: "ALWAYS" } }, { iconPath: "/resources/user.png", id: 1, latitude: res.latitude + 0.1, longitude: res.longitude + 0.1, width: 30, height: 30, alpha: 0.8, callout: { content: " 工程师 ", color: "#ffffff", fontSize: 10, borderRadius: 10, bgColor: "#6e707c", padding: 5, display: "ALWAYS" } } ], }); },});
3、wxss文件
.mapHeight { display: flex; flex-direction: column;}.map { flex: 1; height: 100vh; width: 100%;}
"微信小程序怎么通过API获取当前位置的经纬度"的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注网站,小编将为大家输出更多高质量的实用文章!
位置
坐标
经纬
经纬度
地址
工程
工程师
文件
程序
内容
更多
知识
实用
学有所成
接下来
两个
困境
地图
实际
情况
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
plc软件开发待遇
网络技术改良案例之(十)
数媒专业和计算机网络技术
做网站需要买服务器
召开网络技术措施告知
有哪些好的只读数据库
明日之后服务器要怎么连接
云服务器ecs什么意思
服务器dhcp自动分配ip
63服务器
桌面软件开发语言推荐
联想服务器如何创建两个阵列
sql 强制删除数据库
数据库系统质量保证措施
上海网络安全员证查询系统
济南凌刚网络技术有限公司
家用电脑服务器端口
架设java服务器
服务器吉祥物
网络安全教育预防网络诈骗教案
vmware管理裸金属服务器
数据库第三范式满足的条件
软件开发 维护期
苏宁软件开发值得去吗
学软件开发的男士找什么工作
软件开发运营公司简介
数据库连接地址栏信息
ale ado 数据库
qpcr数据库
服务器维修维保哪家便宜