当前位置: 首页 > 编程日记 > 正文

计算起点地址和终点地址的最短驾车距离和驾车时间

微信小程序开发交流qq群   173683895

   承接微信小程序开发。扫码加微信。

需求:

在一个excel的xlsx表格中有很多起点的地址和终点的地址,要批量计算两个地址之间的距离和驾车时间,按照百度地图的最短距离计算。最后把得出的行驶距离和驾车时间填充至xlsx表格中的相应地址

实现思路:

1.把excel表格中的数据导入数据库

2.通过接口请求数据库,得到所有的起始地址信息并且保存到前端

3.把所有的中午地址转换成经纬度并且存入数据库(因为中午地址是无法直接计算出行驶距离和驾车时间的)

4.请求数据库中的起始点经纬度,计算出行驶距离和驾车时间再保存到数据库

5.数据库导出到excel的xlsx表格,完成

生产场景:

微信小程序开发者工具 + phpstudy + mysql + 百度地图开放平台 - JavaScript API (两个接口,逆/地址解析 和 路线规划)

先建数据库, 结构图如下:产数分别是起点地址,终点地址,距离,时间

小程序前端源码:

var util = require('../../utils/util.js');
// pages/index/index.js
var aa_data, i = 1271,y = 0;
Page({/*** 页面的初始数据*/data: {},// 保存到数据库ddddddd(distance, duration) {var that = this;var data = {duration: duration,distance: distance,sss: this.data.data[i].sss,eee: this.data.data[i].eee,}wx.request({url: 'http://localhost/excel/save.php',data: data,success: function(res) {}})},// 计算起点坐标和终点坐标的最短驾车距离和驾车时间cccccccc(e) {var that = this;var aaa = e.sss.split(',')console.log(aaa)var a_ssss = aaa[1].substring(0, 10) + ',' + aaa[0].substring(0, 10)if (e.eee=='-'){setTimeout(function () {i = i + 1;console.log(i)// that.cccccccc(aa_data[i])}, 300)return}var bbb = e.eee.split(',')console.log(a_ssss)var a_eeee = bbb[1].substring(0, 10) + ',' + bbb[0].substring(0, 10)wx.request({url: 'http://api.map.baidu.com/direction/v2/driving?origin=' + a_ssss + '&destination=' + a_eeee + '&ak=MGIf4Hhwkx9GWrjDh2cVGKk1hQr5tcb8',data: {},success: function(res) {var distance = res.data.result.routes[0].distancevar duration = res.data.result.routes[0].durationconsole.log('最佳路线:', distance + '米', parseInt(duration / 60) + '分钟')that.ddddddd(distance, parseInt(duration / 60))setTimeout(function () {i = i + 1;console.log(i)that.cccccccc(aa_data[i])}, 300)}})},/*** 生命周期函数--监听页面加载*/onLoad: function(options) {var that = this;wx.request({url: 'http://localhost/excel/show.php',data: {location},success: function(res) {console.log(res.data)aa_data = res.datathat.cccccccc(aa_data[i])// that.bbbbbb(aa_data[i].sss)that.setData({data: res.data})}})},// 地址转换成经纬度bbbbbb(add) {var that = this;var url = 'http://api.map.baidu.com/geocoder/v2/';var data = {address: add.length > 35 ? add.substring(0, 35) : add,output: 'json',ak: 'LGPktyrfCarUmfPwDDrL1nG6mlhlkLwA'}util.request(url, 'post', data, '', function(res) {var location = res.data.result.location;console.log(location);wx.request({url: 'http://localhost/excel/sss.php',data: {sss: location.lng + ',' + location.lat,add},success: function(res) {console.log(res.data);console.log(i)i = i + 1;if (i < aa_data.length) {setTimeout(function() {if (aa_data[i].sss == '-') {i = i + 1;that.bbbbbb(aa_data[i].sss)} else {that.bbbbbb(aa_data[i].sss)}}, 300)} else {}}})})},// excel导入数据库aaaaaaaa() {wx.request({url: 'http://localhost/excel/excel.php',data: {location},success: function(res) {console.log(res.data)}})},
})
<!--pages/index/index.wxml-->
<button bindtap='aaaaaaaa'>加载到数据库</button>
<button bindtap='cccccccc'>经纬度计算出时间,路程</button>

后端源码下载 https://download.csdn.net

相关文章:

jmeter测试工具

jmeter的下载&#xff1a; http://jmeter.apache.org/download_jmeter.cgi 1.打开链接选择 Binaries 下.zip下载 下载完后解压 2.然后再下载java中jdk, 配置java的环境变量 JAVA_HOME 和path JAVA_HOME值中加jdk的安装目录 path后面加;%JAVA_HOME%\bin; 3.在jmeter解压目录中…

余数定理_如何用Java实现余数定理

余数定理by Anuj Pahade由Anuj Pahade 如何用Java实现余数定理 (How to implement the Chinese Remainder Theorem in Java) This post assumes that you know what Chinese Remainder Theorem (CRT) is and focuses on its implementation in Java. If you don’t, I’d reco…

C#如何根据DataTable生成泛型List或者动态类型list

背景&#xff1a;在项目中&#xff0c;sql语句检索返回DataTable&#xff0c;然后根据检索结果做进一步的操作&#xff0c;本篇文章即是介绍如何将DataTable快速生成泛型List返回。 假设存在如下学生类&#xff1a; 1 public class student 2 { 3 public int I…

Easyui combobox下拉框默认选中第一项

var val $(#cc).combobox("getData");for (var item in val[0]) { if (item "groupName") { $(this).combobox("select", val[0][item]); }}转载于:https://www.cnblogs.com/AmbiguousMiao/p/7094589.html

js 获取当前时间 随记

微信小程序开发交流qq群 581478349 承接微信小程序开发。扫码加微信。 获取当前时间 new Date().toTimeString().split( )[0];console.log(dete, date) //dete 11:39:46

使用Typescript的巧妙React上下文技巧-不是Redux

by Bill Girten比尔吉尔滕(Bill Girten) 使用Typescript的巧妙React上下文技巧- 不是 Redux (Clever React context tricks using Typescript — not Redux) by Bill Girten, Martin Maza, and Alison Stuart由Bill Girten &#xff0c;Martin Maza和Alison Stuart 撰写 TLDR…

vagrant 介绍,安装与使用

可以帮你统一团队成员的开发环境。如果你或者你的伙伴创建了一个Vagrantfile&#xff0c;那么你只需要执行vagrant up就行了&#xff0c;所有的软件都会安装并且配置好。团队成员可以通过相同的Vagrantfile来创建他们的开发环境&#xff0c;无论他们是在Linux, Mac OS X, 或者W…

HTML元素的基本特性

1&#xff0c;Disabled 特性&#xff1a; 1 //Disabled 设置元素不可用&#xff1a; 2 3 $(this).attr("disabled","disabled") 4 5 //移除push元素的diasble特性&#xff1a; 6 7 $("#push").removeAttr(disabled) 2&#xff0c;z-index 特性…

js base64 解码

微信小程序开发交流qq群 173683895 承接微信小程序开发。扫码加微信。 解码函数 function base64_decode (input) { // 解码&#xff0c;配合decodeURIComponent使用var base64EncodeChars "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789/";…

esl8266开发之旅_从ESL老师到越南软件开发人员的旅程

esl8266开发之旅by alberto montalesi通过阿尔贝托蒙塔莱西 从ESL老师到越南软件开发人员的旅程 (My Journey from an ESL Teacher to Software Developer in Vietnam) 介绍 (Introduction) Hi, my name is Alberto, and this is the story of how I learned to code, wrote a…

洛谷P2429 制杖题 [2017年6月计划 数论10]

P2429 制杖题 题目描述 求不大于 m 的、 质因数集与给定质数集有交集的自然数之和。 输入输出格式 输入格式&#xff1a;第一行二个整数 n&#xff0c;m。 第二行 n 个整数&#xff0c;表示质数集内的元素 p[i]。 输出格式&#xff1a;一个整数&#xff0c;表示答案&#xff0c…

微信小程序框架封装登录,网络请求等公共模块及调用示例

微信小程序开发交流qq群 173683895 承接微信小程序开发。扫码加微信。 这个公共模块封装了session的获取&#xff0c;和fromId发送&#xff0c;showToast成功和失败的弹窗。 微信小程序公共通用模块 const util require(../utils/util.js);function init() {var that th…

安装centos后无法引导启动windows7的解决方法

在电脑Windows7系统上安装Centos7&#xff0c;安装后找不到Windows7引导菜单。 原因&#xff1a;因为CentOS 7已采用新式的grub2系统&#xff0c;所以需要进入/boot/grub2目录后使用vi编辑grub.cfg文件。 解决方法一&#xff1a;修改Centos 7的Grub2引导&#xff0c;添加Window…

git最佳实践_Git最佳实践如何为我节省大量的返工时间

git最佳实践by Hemal Patel通过赫马尔帕特尔 Git最佳实践如何为我节省大量的返工时间 (How Git best practices saved me hours of rework) Recently I was working on the task to upgrade a certificate for a NodeJS application. This was last touched two years ago for…

商品列表选择尺寸和颜色高亮,并且把选择的数据传递到下一个页面

微信小程序开发交流qq群 173683895 承接微信小程序开发。扫码加微信。 需求&#xff1a;商品列表选择属性&#xff0c;给中的属性显示高亮&#xff0c;并且把选择的数据记录下来传递到下一个页面。 项目下载地址&#xff1a;点击去下载 效果图&#xff1a; 选择商品的属性…

Android studio 使用心得(三)—从Eclipse迁移到Android studio

断断续续的也算是把eclipse上的代码成功迁移到android studio上来了&#xff0c;现在&#xff0c;我同事继续用eclipse&#xff0c;我用android studio&#xff0c;svn上还是之前eclipse的项目&#xff0c;迁移成功后&#xff0c;我也能happy的开发了,两不误.直接来分享我捉摸的…

代码改变世界_改变世界,一次只写一行代码

代码改变世界People like to look at changing the world as a big task. I believe changing the world can be done in little steps.人们喜欢将改变世界视为一项艰巨的任务。 我相信&#xff0c;改变世界可以一步步完成。 The key is identifying a problem and taking a l…

14_传智播客iOS视频教程_instancetype

12312312转载于:https://www.cnblogs.com/ZHONGZHENHUA/p/7097094.html

HDU 1011-Starship Troopers(树形背包)

题意&#xff1a; 有n个洞&#xff0c;连接像一棵树&#xff0c;每个包含一定数量的怪和价值&#xff0c;给你m个士兵&#xff0c;每个士兵能打20个怪&#xff0c;杀完一个洞的怪可得该洞的价值才可继续打相连的下面的洞&#xff08;每个士兵只能打一个洞&#xff09;&#xff…

微信小程序自定义组件之Picker组件

微信小程序开发交流qq群 173683895 承接微信小程序开发。扫码加微信。 需求&#xff1a; 通过JS条件判断&#xff0c;满足条件就弹出Picker给用户选择一个数组里面的数据。 有些朋友可能会有疑问&#xff1a; 1.为什么要使用自定义的Picker组件&#xff0c;不是有原生的组…

kotlin ++ --_顺便说一句-探索Kotlin代表团

kotlin --by Adam Arold亚当阿罗德(Adam Arold) 顺便说一句-探索Kotlin代表团 (By the way — exploring delegation in Kotlin) Kotlin has an interesting keyword, by, which can be used for delegation. There is a lot of confusion around it, so in this article we’…

网页制作之html基础学习3-css样式表

样式&#xff1a;CSS&#xff08;Cascading Style Sheets,层叠样式表&#xff09;&#xff0c;作用是美化HTML网页。 在样式里面用 /* */ 进行注释。 1、样式表的基本概念 1.1、样式表分类 1、内联样式表 和html联合显示&#xff0c;控制精确&#xff0c;但是可重用性差&#…

Mac OS X 下查看和设置JAVA_HOME

原文链接 : http://blog.csdn.net/done58/article/details/51138057 1, 查看Java版本 打开Mac电脑&#xff0c;查看JAVA版本&#xff0c;打开终端Terminal&#xff0c;通过命令行查看笔者的java版本&#xff1a;&#xff1a; [html] view plaincopy bogon:~ donny$ java -vers…

微信小程序获取用户设备的信息

微信小程序开发交流qq群 173683895 承接微信小程序开发。扫码加微信。 可以获取用户的手机型号&#xff0c;手机操作系统&#xff0c;微信版本&#xff0c;屏幕宽高等等。 Object wx.getSystemInfoSync() wx.getSystemInfo 的同步版本 返回值 Object res 属性类型说明最…

php 命令执行crud_如何使用原始JavaScript执行CRUD操作

php 命令执行crudby Zafar Saleem通过Zafar Saleem 如何使用原始JavaScript执行CRUD操作 (How to perform CRUD operations using vanilla JavaScript) Nowadays there are a number of JavaScript frameworks around such as React, Angular, Vue and so on. They all offer …

关于手机系统信息的总结

获取IMEI号: /*** 获取IMEI号* * Description:* param param activity* param return* return String*/public static String getIMEI(Activity activity) {TelephonyManager manager (TelephonyManager) activity.getSystemService(Context.TELEPHONY_SERVICE);return manage…

pat1011. World Cup Betting (20)

1011. World Cup Betting (20) 时间限制400 ms内存限制65536 kB代码长度限制16000 B判题程序Standard作者CHEN, YueWith the 2010 FIFA World Cup running, football fans the world over were becoming increasingly excited as the best players from the best teams doing b…

如何清空定时器

微信小程序开发交流qq群 173683895 承接微信小程序开发。扫码加微信。 看代码 var aaaa; //利用slice function truncate(arr) {return arr.slice(0, -1); } Page({data: {},onShow() {console.log(yyyyyyyyyyyyyyyyyyy)clearInterval(aaaa)aaaa setInterval(function () {…

如何解决JavaScript中的根查找

介绍 (Introduction) I’ve been wanting to write about this topic for a while now. I recently had the opportunity to work on simulating the GoalSeek functionality of Excel for a web application. I found the whole purpose of GoalSeek and how it works fascina…

菜单样式1:鼠标悬停向下弹出列表

JS部分&#xff1a;var qcloud{};$([_t_nav]).hover(function(){var _nav $(this).attr(_t_nav);clearTimeout( qcloud[ _nav _timer ] );qcloud[ _nav _timer ] setTimeout(function(){$([_t_nav]).each(function(){$(this)[ _nav $(this).attr(_t_nav) ? addClass:remo…