迷你马拉松线路规划,前端,lbs

2023-10-24 03:21

本文主要是介绍迷你马拉松线路规划,前端,lbs,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

我设计了迷你拉松路线规划工具。在微信小程序里,使用qqmap-wx-jssdk.js接口,通过在地图上加入途径的坐标,把每个节点串成一个完整的线路。

同时用POI在点击的时候显示每个节点真实的地名,并计算总路程。

首先要定义初始变量和onLoad函数

var app = getApp();
const QQMapWX = require('../../../../we7/js/qqmap-wx-jssdk.js');
var qqmapsdk;Page({data: {banner: [],url: [],navTile: "创建线路",curIndex: 0,nav: ["组队中", "已组队"],curList: [],oldList: [],page: 1,oldpage: 1,group: [1],usrgroup: [1, 2, 3],lat: 28.65857270312306,lng: 121.41610499450682,markers: [],teamnum:[3,4,5,6,7,8,9,10],objectteamnum: [{id: 3,name: '3人'},{id: 4,name: '4人'},{id: 5,name: '5人'},{id: 6,name: '6人'},{id: 7,name: '7人'},{id: 8,name: '8人'},{id: 9,name: '9人'},{id: 10,name: '10人'},],index: 0,time: '18:00',longitude:0,latitude:0,multiIndex: [0, 0, 0],polyline:[],pointer: [{num: 0,key: 0,color: 'none'}],node:[],beforenode:0,pl:[],distance:[],address:'',finish_line:''},onLoad: function(t) {var a = this;wx.setNavigationBarTitle({title: a.data.navTile});},

为了突出重点我省略了表单提交部分代码,直奔主题

//  qqmap api 加入坐标
putdot(e) {var that = thisthat.mapCtx = wx.createMapContext("map4select");that.mapCtx.getCenterLocation({type: 'gcj02',success: function(e) {//放入坐标点位var markers = {iconPath: "/style/images/mapine.png",id: that.data.markers.length,latitude: e.latitude,longitude: e.longitude,width: 35,height: 35}//创建路径qqmapsdk = new QQMapWX({key: '我的api密钥'});// 只能在市民广场范围内5公里的跑步qqmapsdk.calculateDistance({from: '28.65857270312306,121.41610499450682' || '',to: e.latitude + ',' + e.longitude, //终点坐标success: function (res) {//成功后的回调var res = res.result;var dis = [];for (var i = 0; i < res.elements.length; i++) {dis.push(res.elements[i].distance); //将返回数据存入dis数组,}var long = that.formatDistance2(dis[0])console.log(long)if(long>3){wx.showToast({title: '圆圈内选择线路',icon: '',image: '',duration: 1000,mask: true,success: function(res) {that.setData({circles: [{latitude: 28.65857270312306,longitude: 121.41610499450682,color: '#78daf5',fillColor: '#ffffff00',radius: 2600, //定位点半径strokeWidth: 1}],})},fail: function(res) {},complete: function(res) {},})return}else{}var pl = that.data.plvar latitude=that.data.latitudevar longitude=that.data.longitudeif(latitude){that.aquadrs2(e)qqmapsdk.direction({mode: 'walking',//可选值:'driving'(驾车)、'walking'(步行)、'bicycling'(骑行),不填默认:'driving',可不填//from参数不填默认当前地址from: latitude+','+longitude,to: e.latitude + ',' + e.longitude, //终点坐标success: function (fe) {console.log(12345)console.log(fe);var distance=that.data.distancedistance.push(fe.result.routes[0].distance)//   合计距离var distancesum=that.sum(distance)/1000var ret = fe;var coors = ret.result.routes[0].polyline, pl = that.data.pl,node=that.data.node;//坐标解压(返回的点串坐标,通过前向差分进行压缩)var kr = 1000000;for (var i = 2; i < coors.length; i++) {coors[i] = Number(coors[i - 2]) + Number(coors[i]) / kr;}//将解压后的坐标放入点串数组pl中for (var i = 0; i < coors.length; i += 2) {pl.push({ latitude: coors[i], longitude: coors[i + 1] })}var beforenode=that.data.beforenodevar afternodeif(beforenode&&node!=''){afternode=pl.lengthnode.push(pl.length-beforenode)}else{afternode=pl.lengthnode.push(pl.length)}console.log(pl)//设置polyline属性,将路线显示出来,将解压坐标第一个数据作为起点that.setData({latitude:pl[pl.length-1].latitude,longitude:pl[pl.length-1].longitude,polyline: [{points: pl,color: '#FF0000DD',arrowLine:true,width: 5}],node:node,pl:pl,beforenode:afternode,distance:distance,distancesum:distancesum})},fail: function (error) {console.error(error);},});}else{that.aquadrs(e)that.setData({latitude:e.latitude,longitude:e.longitude})}console.log(that.data.markers)that.data.markers.push(markers)that.setData({markers: that.data.markers,})},});}})//console.log(that.data.pointer)},

从上往下说明,putdot(放置坐标点),makers(坐标点对象),calculateDistance(线路只能在市民广场5公里范围内进行),dis(距离),formatDistance2(计算公里数),long>3(超过范围,绘制圆圈提示),latitude(获取初始经纬度,如果非空开始规划路线),aquadrs2(获取终点地址),walking(选择的是步行计算方式)  ,e.latitude和e.longitud(获得的坐标),distance(初始化距离,数组每个元素都是一段距离),distancesum(计算总长度),pl(已有的路径),node(每次路径的节点数存入数组),coors(最新的路径),pl.push(新路径的传入数组),beforenode(之前的节点长度),afternode(之后的节点长度,如果beforenode为空就进行),pl.length-beforenode(当前路径的节点数量),setData(把最新的经纬度保存一下,设置路径,node每个节点长度的数组,路径的数组,用新的afternode替换beforenode,distance每段距离的数组,distancesum距离的统计数值)

else里,latitude(确定起点坐标),aquadrs(获取起点的地址名称),markers(一开始回调得到的定位),that.data.markers(默认坐标)

补充撤销操作函数

  sum(arr){var a=0for(var s in arr){a+=arr[s]}console.log(a)return a},
//   获取起点地址aquadrs(e) {var _this = this;qqmapsdk.reverseGeocoder({location: e.latitude + ',' + e.longitude || '', //获取表单传入的位置坐标,不填默认当前位置,示例为string格式//get_poi: 1, //是否返回周边POI列表:1.返回;0不返回(默认),非必须参数success: function(res) {//成功后的回调console.log(res);var res = res.result;var mks = [];mks.push({ // 获取返回结果,放到mks数组中title: res.address,id: 0,latitude: res.location.lat,longitude: res.location.lng,iconPath: '/style/images/5.png',//图标路径width: 20,height: 20,//   callout: {//     content: res.address,//     color: '#000',//     display: 'ALWAYS'//   }});_this.setData({ //设置markers属性和地图位置poi,将结果在地图展示markers: mks,address:res.address,poi: {latitude: res.location.lat,longitude: res.location.lng}});},fail: function(error) {console.error(error);},complete: function(res) {console.log(res);}})},//   获取地址aquadrs2(e) {var _this = this;qqmapsdk.reverseGeocoder({location: e.latitude + ',' + e.longitude || '', //获取表单传入的位置坐标,不填默认当前位置,示例为string格式//get_poi: 1, //是否返回周边POI列表:1.返回;0不返回(默认),非必须参数success: function(res) {//成功后的回调console.log(res);var res = res.result;var mks = [];mks.push({title: res.address,id: 0,latitude: res.location.lat,longitude: res.location.lng,iconPath: '/style/images/hklogo.png',width: 20,height: 20,});_this.setData({ //设置markers属性和地图位置poi,将结果在地图展示//   markers: mks,finish_line:res.address,poi: {latitude: res.location.lat,longitude: res.location.lng}});},fail: function(error) {console.error(error);},complete: function(res) {console.log(res);}})},undo2(){var that=this//start deletenumber splice//start end slicevar node = that.data.nodethat.data.markers.splice(-1)that.data.pl.splice(-node[node.length-1])that.data.node.splice(-1)that.data.distance.splice(-1)//node和pl同时清空,marker点比他们多一个,所以最后起始点应该再撤销一次console.log('undo '+node[node.length-1])that.setData({node: that.data.node,polyline: [{points: that.data.pl,color: '#FF0000DD',arrowLine:true,width: 5}],markers: that.data.markers,distance:that.data.distance})console.log(that.data.markers.length-1)//marker点比路径数组多一个值if(that.data.markers.length>0){that.setData({latitude:that.data.markers[that.data.markers.length-1]['latitude'],longitude:that.data.markers[that.data.markers.length-1]['longitude']    })}else{that.setData({latitude:0,longitude:0})}},formatDistance(num) {if (num < 1000) {return num.toFixed(0) + 'm';} else if (num > 1000) {return (num / 1000).toFixed(1) + 'km';}},formatDistance2(num) {return (num / 1000).toFixed(1)}
});

通过修改markers,pl,node规划路线

这篇关于迷你马拉松线路规划,前端,lbs的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



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

相关文章

Vue3 的 shallowRef 和 shallowReactive:优化性能

大家对 Vue3 的 ref 和 reactive 都很熟悉,那么对 shallowRef 和 shallowReactive 是否了解呢? 在编程和数据结构中,“shallow”(浅层)通常指对数据结构的最外层进行操作,而不递归地处理其内部或嵌套的数据。这种处理方式关注的是数据结构的第一层属性或元素,而忽略更深层次的嵌套内容。 1. 浅层与深层的对比 1.1 浅层(Shallow) 定义

这15个Vue指令,让你的项目开发爽到爆

1. V-Hotkey 仓库地址: github.com/Dafrok/v-ho… Demo: 戳这里 https://dafrok.github.io/v-hotkey 安装: npm install --save v-hotkey 这个指令可以给组件绑定一个或多个快捷键。你想要通过按下 Escape 键后隐藏某个组件,按住 Control 和回车键再显示它吗?小菜一碟: <template

【 html+css 绚丽Loading 】000046 三才归元阵

前言:哈喽,大家好,今天给大家分享html+css 绚丽Loading!并提供具体代码帮助大家深入理解,彻底掌握!创作不易,如果能帮助到大家或者给大家一些灵感和启发,欢迎收藏+关注哦 💕 目录 📚一、效果📚二、信息💡1.简介:💡2.外观描述:💡3.使用方式:💡4.战斗方式:💡5.提升:💡6.传说: 📚三、源代码,上代码,可以直接复制使用🎥效果🗂️目录✍️

【前端学习】AntV G6-08 深入图形与图形分组、自定义节点、节点动画(下)

【课程链接】 AntV G6:深入图形与图形分组、自定义节点、节点动画(下)_哔哩哔哩_bilibili 本章十吾老师讲解了一个复杂的自定义节点中,应该怎样去计算和绘制图形,如何给一个图形制作不间断的动画,以及在鼠标事件之后产生动画。(有点难,需要好好理解) <!DOCTYPE html><html><head><meta charset="UTF-8"><title>06

动态规划---打家劫舍

题目: 你是一个专业的小偷,计划偷窃沿街的房屋。每间房内都藏有一定的现金,影响你偷窃的唯一制约因素就是相邻的房屋装有相互连通的防盗系统,如果两间相邻的房屋在同一晚上被小偷闯入,系统会自动报警。 给定一个代表每个房屋存放金额的非负整数数组,计算你 不触动警报装置的情况下 ,一夜之内能够偷窃到的最高金额。 思路: 动态规划五部曲: 1.确定dp数组及含义 dp数组是一维数组,dp[i]代表

软考系统规划与管理师考试证书含金量高吗?

2024年软考系统规划与管理师考试报名时间节点: 报名时间:2024年上半年软考将于3月中旬陆续开始报名 考试时间:上半年5月25日到28日,下半年11月9日到12日 分数线:所有科目成绩均须达到45分以上(包括45分)方可通过考试 成绩查询:可在“中国计算机技术职业资格网”上查询软考成绩 出成绩时间:预计在11月左右 证书领取时间:一般在考试成绩公布后3~4个月,各地领取时间有所不同

poj 2976 分数规划二分贪心(部分对总体的贡献度) poj 3111

poj 2976: 题意: 在n场考试中,每场考试共有b题,答对的题目有a题。 允许去掉k场考试,求能达到的最高正确率是多少。 解析: 假设已知准确率为x,则每场考试对于准确率的贡献值为: a - b * x,将贡献值大的排序排在前面舍弃掉后k个。 然后二分x就行了。 代码: #include <iostream>#include <cstdio>#incl

计算机毕业设计 大学志愿填报系统 Java+SpringBoot+Vue 前后端分离 文档报告 代码讲解 安装调试

🍊作者:计算机编程-吉哥 🍊简介:专业从事JavaWeb程序开发,微信小程序开发,定制化项目、 源码、代码讲解、文档撰写、ppt制作。做自己喜欢的事,生活就是快乐的。 🍊心愿:点赞 👍 收藏 ⭐评论 📝 🍅 文末获取源码联系 👇🏻 精彩专栏推荐订阅 👇🏻 不然下次找不到哟~Java毕业设计项目~热门选题推荐《1000套》 目录 1.技术选型 2.开发工具 3.功能

Vue3项目开发——新闻发布管理系统(六)

文章目录 八、首页设计开发1、页面设计2、登录访问拦截实现3、用户基本信息显示①封装用户基本信息获取接口②用户基本信息存储③用户基本信息调用④用户基本信息动态渲染 4、退出功能实现①注册点击事件②添加退出功能③数据清理 5、代码下载 八、首页设计开发 登录成功后,系统就进入了首页。接下来,也就进行首页的开发了。 1、页面设计 系统页面主要分为三部分,左侧为系统的菜单栏,右侧

代码随想录冲冲冲 Day39 动态规划Part7

198. 打家劫舍 dp数组的意义是在第i位的时候偷的最大钱数是多少 如果nums的size为0 总价值当然就是0 如果nums的size为1 总价值是nums[0] 遍历顺序就是从小到大遍历 之后是递推公式 对于dp[i]的最大价值来说有两种可能 1.偷第i个 那么最大价值就是dp[i-2]+nums[i] 2.不偷第i个 那么价值就是dp[i-1] 之后取这两个的最大值就是d