微信小程序 循迹功能制作
规划地图的路径,实时获取用户当前的定位,进行路线循迹导航功能的开发:
效果图:
实现代码:
<map id="map" enable-satellite longitude="{{longitude1}}" latitude="{{latitude1}}" scale="{{scale}}" controls="{{controls}}" bindcontroltap="controltap" markers="{{markers}}" bindmarkertap="markertap" polyline="{{polyline}}" bindregionchange="regionchange" show-location style="width: 100%; height: 348px;"></map><view class="title">路线:{{title}}</view>
<view style="margin-top: 20rpx;"></view><button type='primary' catchtap="start_dian">路线起点开始循迹</button>
<button type='primary' catchtap="end_dian">路线终点开始循迹</button>
<button type='primary' catchtap="dom">下载</button>
var that;
const app = getApp()
const util = require("../../utils/util.js")
const txt = require("../../utils/txt.js")
// const txt = require("../../utils/gcoord.js")
import gcoord from '../../utils/gcoord.js'
var polyline_points = [];
var x_PI = 3.14159265358979324 * 3000.0 / 180.0;var PI = 3.1415926535897932384626;var a = 6378245.0;var ee = 0.00669342162296594323;
Page({data: {pageShow:false,scale:10,obj: {},longitude: 116.34665554470486,latitude: 39.9463560655382,in_val: '',showModalStatus: false,key: 'sadsad',markers: [{iconPath: "/img/map.png",id: 0,longitude: 116.34903966083392,latitude: 39.94907287783573,width: 30,height: 30}, {iconPath: "/img/map.png",id: 0,longitude: 116.3431299221213,latitude: 39.94493766291209,width: 30,height: 30}, {iconPath: "/img/map.png",id: 0,longitude: 116.34090281579688,latitude: 39.946849743723874,width: 30,height: 30}],polyline: [{points: [],color: "#3F51B5",width: 5,}],},dom(){wx.navigateTo({url: '../myList/myList',})},// 设置地图路线setMapXian() {var kmlLines = this.data.obj.kmlLines.points;kmlLines.forEach((item, idx) => {// if (idx <= 1000) {this.setMapItemPoints(item.longitude, item.latitude, idx)// }})},// 设置路线setMapItemPoints(longitude, latitude, idx) {var result = gcoord.transform([longitude, latitude], // 经纬度坐标gcoord.WGS84, // 当前坐标系(百度)gcoord.GCJ02); console.log('result', result)var points = {longitude: result[0],latitude: result[1]}polyline_points.push(points)// console.log('设置路线', polyline_points, longitude, latitude)// 设置地图标记点if (idx == this.data.obj.kmlLines.points.length-1) {// 终点坐标this.setMapItemMarkers(result[0], result[1])this.setData({['polyline[0].points']: polyline_points,zhongdian_longitude: result[0],zhongdian_latitude: result[1]})} else if (idx ==0){// 起点坐标this.setMapItemMarkers(result[0], result[1])this.setData({qidian_longitude: result[0],qidian_latitude: result[1]})}},// 从路线起点开始循迹start_dian() {var longitude1 = this.data.qidian_longitudevar latitude1 = this.data.qidian_latitudethis.setData({scale: 15,longitude1: longitude1,latitude1: latitude1,})},// 从路线终点开始循迹end_dian() {var longitude1 = this.data.zhongdian_longitudevar latitude1 = this.data.zhongdian_latitudethis.setData({scale: 15,longitude1: longitude1,latitude1: latitude1,})},// 点击当前位置now_loction() {var that=this;wx.getLocation({type: 'wgs84',success(res) {const latitude = res.latitudeconst longitude = res.longitudethat.setData({longitude1: longitude,latitude1: latitude,})}})},// 导航daohang(daohang_latitude, daohang_longitude) {console.log(daohang_latitude, daohang_longitude)wx.openLocation({latitude: daohang_latitude,longitude: daohang_longitude,scale: 10})},// 导航到起点navigation_start_ll() {var trackPoints = this.data.obj.trackPointsvar start_latitude = trackPoints[0].points.latitudevar start_longitude = trackPoints[0].points.altitudethis.daohang(start_latitude, start_longitude);},// 导航到终点navigation_end_ll() {var trackPoints = this.data.obj.trackPointsvar end_latitude = trackPoints[1].points.latitudevar end_longitude = trackPoints[1].points.altitudethis.daohang(end_latitude, end_longitude);},onLoad(options) {var obj = {};console.log('txt:', txt)options.title = "洗马林长城导航轨迹";txt.forEach(item => {if (item.title == options.title) {console.log('1111111111111111')obj = item} else {console.log('22222222222222222', item.title, options, options.title)}})console.log('obj:', obj)this.setData({title: options.title,obj})var trackPoints = this.data.obj.trackPointsvar start_latitude = trackPoints[0].points.latitudevar start_longitude = trackPoints[0].points.altitudeconsole.log('11111111',trackPoints,start_latitude, start_longitude)this.setData({latitude1: start_latitude,longitude1: start_longitude})this.setMapXian()},// 设置起点终点坐标setMapItemMarkers(longitude, latitude) {var obj_item = {iconPath: "/img/map.png",id: 0,longitude: longitude,latitude: latitude,width: 30,height: 30};var markers = this.data.markers;markers.push(obj_item);this.setData({markers})return obj_item;},// 设置地图绿色的点map_ll(nowTime) {const _locationChangeFn = res => {console.log('location change', res.latitude, res.longitude)if (nowTime) {nowTime = falsethis.setData({latitude1: res.latitude,longitude1: res.longitude})}}wx.onLocationChange(_locationChangeFn);},onShow() {this.getUserLocation();},markertap(e) {console.log(e.markerId)this.showModal(e.markerId)},controltap(e) {console.log(e.controlId)},getUserLocation() {wx.getSetting({success(res) {console.log(res)if (res.authSetting['scope.userLocationBackground']) {wx.startLocationUpdateBackground({success: (res) => {console.log('startLocationUpdate-res', res)},fail: (err) => {console.log('startLocationUpdate-err', err)}})} else {if (res.authSetting['scope.userLocation'] == false) {console.log('打开设置页面去授权')} else {wx.startLocationUpdateBackground({success: (res) => {console.log('startLocationUpdate-res', res)},fail: (err) => {console.log('startLocationUpdate-err', err)}})}}}})},//显示对话框showModal: function(idx) {//console.log(event.markerId);var myall = {longitude: this.data.list[idx].longitude,latitude: this.data.list[idx].latitude,tel: this.data.list[idx].linktel,name: this.data.list[idx].name,introduce: this.data.list[idx].introduce,linkName: this.data.list[idx].linkName,time: util.js_date_time(new Date().getTime() / 1000),id: idx,}this.setData({myall})var that = this;// 显示遮罩层var animation = wx.createAnimation({duration: 200,timingFunction: "linear",delay: 0})this.animation = animationanimation.translateY(300).step()this.setData({animationData: animation.export(),showModalStatus: true})setTimeout(function() {animation.translateY(0).step()this.setData({animationData: animation.export()})}.bind(this), 200)},//隐藏对话框hideModal: function() {// 隐藏遮罩层var animation = wx.createAnimation({duration: 200,timingFunction: "linear",delay: 0})this.animation = animationanimation.translateY(300).step()this.setData({animationData: animation.export(),})setTimeout(function() {animation.translateY(0).step()this.setData({animationData: animation.export(),showModalStatus: false})}.bind(this), 200)},calling: function(event) {var tel = this.data.myall.tel;wx.makePhoneCall({phoneNumber: tel,success: function() {console.log("拨打电话成功!")},fail: function() {console.log("拨打电话失败!")}})},nav_register() {wx.navigateTo({url: '../register/register',})},regionchange(e) {if (e.type == 'end' && (e.causedBy == 'scale' || e.causedBy == 'drag')) {// console.log(e) var that = this;this.mapCtx = wx.createMapContext("map");this.mapCtx.getCenterLocation({type: 'gcj02',success: function(res) {var coordinate = that.gcj02towgs84(res.longitude, res.latitude) ;console.log(coordinate, 2222)that.setData({lat2: res.latitude.toFixed(6),lng2: res.longitude.toFixed(6),circles: [{latitude: res.latitude,longitude: res.longitude,color: '#FF0000DD',fillColor: '#d1edff88',radius: 0, //定位点半径 strokeWidth: 1}]})}})}},out_of_china(lng, lat) {return (lng < 72.004 || lng > 137.8347) || ((lat < 0.8293 || lat > 55.8271) || false);},gcj02towgs84(lng, lat) {var that = this;if (that.out_of_china(lng, lat)) {return [lng, lat]} else {var dlat = that.transformlat(lng - 105.0, lat - 35.0);var dlng = that.transformlng(lng - 105.0, lat - 35.0);var radlat = lat / 180.0 * PI;var magic = Math.sin(radlat);magic = 1 - ee * magic * magic;var sqrtmagic = Math.sqrt(magic);dlat = (dlat * 180.0) / ((a * (1 - ee)) / (magic * sqrtmagic) * PI);dlng = (dlng * 180.0) / (a / sqrtmagic * Math.cos(radlat) * PI);var mglat = lat + dlat;var mglng = lng + dlng;return [lng * 2 - mglng, lat * 2 - mglat]}},transformlat(lng, lat) {var ret = -100.0 + 2.0 * lng + 3.0 * lat + 0.2 * lat * lat + 0.1 * lng * lat + 0.2 * Math.sqrt(Math.abs(lng));ret += (20.0 * Math.sin(6.0 * lng * PI) + 20.0 * Math.sin(2.0 * lng * PI)) * 2.0 / 3.0;ret += (20.0 * Math.sin(lat * PI) + 40.0 * Math.sin(lat / 3.0 * PI)) * 2.0 / 3.0;ret += (160.0 * Math.sin(lat / 12.0 * PI) + 320 * Math.sin(lat * PI / 30.0)) * 2.0 / 3.0;return ret},transformlng(lng, lat) {var ret = 300.0 + lng + 2.0 * lat + 0.1 * lng * lng + 0.1 * lng * lat + 0.1 * Math.sqrt(Math.abs(lng));ret += (20.0 * Math.sin(6.0 * lng * PI) + 20.0 * Math.sin(2.0 * lng * PI)) * 2.0 / 3.0;ret += (20.0 * Math.sin(lng * PI) + 40.0 * Math.sin(lng / 3.0 * PI)) * 2.0 / 3.0;ret += (150.0 * Math.sin(lng / 12.0 * PI) + 300.0 * Math.sin(lng / 30.0 * PI)) * 2.0 / 3.0;return ret},})
map{margin-top: 30rpx;
}
button{margin-bottom: 10rpx;width: 80%;margin-left: 10%;}
.title{margin: 30rpx;font-size: 45rpx;
}
.detail{margin-left: 30rpx;font-size: 38rpx;color: #999;margin: 20rpx 20rpx 20rpx 30rpx;
}
.top{padding: 30rpx;
}
.top view{margin-bottom: 10rpx;border-bottom: 1px solid;
}
input{margin-top: 10rpx;
}
.in_val{margin: 20rpx;border: 1px solid #d0d0d0;width: 340rpx;height: 60rpx;padding-left: 10rpx;border-radius: 5rpx;
}
.btn{height: 64rpx;margin-top: 20rpx;font-size: 30rpx;line-height: 64rpx;
}
.input_block{display: flex;flex-direction: row;
}
.aaa{margin-top: 20rpx;margin-left: 20rpx;background: darkorange;padding: 10rpx 30rpx 10rpx 30rpx;width: 200rpx;border-radius: 10rpx;color: white;
}
.bbb{top: 20rpx;margin-left: 20rpx;position: absolute;right: 30rpx;background: darkorange;padding: 10rpx 30rpx 10rpx 30rpx;width: 200rpx;border-radius: 10rpx;color: white;
}
.nav_register{background: #7DD43C;color: white;position: absolute;/* margin-top: 10rpx; */right: 30rpx;padding: 5rpx 20rpx 5rpx 20rpx;border-radius: 5rpx;
}
.nav_register2{background: #7DD43C;color: white;position: absolute;/* margin-top: 10rpx; */right: 230rpx;padding: 5rpx 20rpx 5rpx 20rpx;border-radius: 5rpx;
}
.c_icon{position: fixed;top: 50%;left: 50%;width: 50rpx;height: 60rpx;margin-top: -35rpx;margin-left: -30rpx;
}
/* index/index.wxss */
page{height: 100%;
}
.index_bt1{width: 100rpx;height: 100rpx;padding-top:30rpx;margin-left: 600rpx;
}.xiaoer{width: 100rpx;height: 100rpx;
}.index_shuaxin{width: 60rpx;height: 60rpx;padding-top: 860rpx;margin-left: 20rpx;
}.shuaxin{width: 60rpx;height: 60rpx;
}.sch{display: block;z-index: 999999;height: 69rpx;width:100%; margin:0 auto;padding-top: 30rpx;
}/*底部弹窗开始 -使屏幕变暗 */
.commodity_screen {width: 100%;height: 100%;position: fixed;top: 0;left: 0;background: #000;opacity: 0.2;overflow: hidden;z-index: 1000;color: #fff;
}
/*对话框 */
.commodity_attr_box {height: 280rpx;width: 100%;overflow: hidden;position: fixed;bottom: 0;left: 0;z-index: 2000;background: #fff;padding-top: 0rpx;
}.placeBox{width: 100%;height: 150rpx;
}.placeViewLt{display: inline-block;width: 620rpx;height: 140rpx;vertical-align: middle;
}.viewTitle{display: block;font-size: 38rpx;color: #3F51B5;margin-left: 20rpx;padding-top: 34rpx;
}.viewDis{display: inline-block;font-size: 26rpx;color: gray;margin-left: 20rpx;
}.viewAddr{display: inline-block;font-size: 28rpx;color: gray;margin-left: 20rpx;
}.placeViewRt{display: inline-block;width: 120rpx;height: 120rpx;padding-top: 6rpx;vertical-align: middle;
}.viewIcon{display: block;height: 100rpx;width: 100%;border-top: 1px solid #ebebeb;padding-top: 40rpx;
}.indexIcon{display: inline-block;width: 50rpx;height: 50rpx;margin-left: 40rpx;margin-top: -26rpx;vertical-align: middle;
}.timeText{display: inline-block;line-height: 45rpx;margin-left: 12rpx;text-align: center;width: 200rpx;height: 45rpx;background-color: rgb(230, 234, 255);border-radius: 10px;color: #3F51B5;font-size: 24rpx;
}.indexIcon1{display: inline-block;width: 50rpx;height: 50rpx;margin-top: -10rpx;margin-left: 110rpx;vertical-align: middle;
}.indexIcon2{display: inline-block;width: 50rpx;margin-top: -10rpx;height: 50rpx;margin-left: 20rpx;vertical-align: middle;
}.timeText1{display: inline-block;line-height: 45rpx;margin-left: 12rpx;width: 100rpx;height: 45rpx;color: #3F51B5;font-size: 24rpx;
}.timeText2{display: inline-block;line-height: 45rpx;margin-left: 12rpx;width: 200rpx;height: 45rpx;color: #3F51B5;font-size: 24rpx;
}
.btn-area{ width: 100%;}
.btn_no{ float:left;width: 40%; margin-left: 5%;border: 0px;}
.btn_ok{ float:left;width: 40%; margin-left: 10%;margin-right: 5%; border: 0px;}
相关文章:

DOM解析和SAX解析的区别
DOM解析和SAX解析的区别 博客分类: XMLDOM SAX DOM解析和SAX解析的区别 No区 别DOM解析SAX解析1操作将所有文件读取到内存中形成DOM树,如果文件量过大,则无法使用顺序读入所需要的文件内容,不会一次性全部读取,不受文件…

java编写代码用什么_如何学习用Java编写代码:为什么要学习以及从哪里开始
java编写代码用什么by John Selawsky约翰塞劳斯基(John Selawsky) 如何学习用Java编写代码:为什么要学习以及从哪里开始 (How to learn to code in Java: why you should and where to start) Define your career goals and choose a language. This is the most i…

迷宫寻宝(搜索)
迷宫寻宝(一) 时间限制:1000 ms | 内存限制:65535 KB难度:4描述一个叫ACM的寻宝者找到了一个藏宝图,它根据藏宝图找到了一个迷宫,这是一个很特别的迷宫,迷宫里有N个编过号的门&…

理解Python的迭代器(转)
原文地址: http://python.jobbole.com/81916/ 另外一篇文章: http://www.cnblogs.com/kaituorensheng/p/3826911.html 什么是迭代 可以直接作用于for循环的对象统称为可迭代对象(Iterable)。 可以被next()函数调用并不断返回下一个值的对象称为迭代器(Iterator)。 所有的Iterab…

快捷导航动画制作
做了一个仿大众点评的快捷导航动画效果,点击导航内的箭头,导航缩放,点击快捷导航再伸展。 看效果图: 实现代码: <block wx:if"{{!isCustom}}"><view class"home_and_reSource" animati…

instant apps_Android Instant Apps 101:它们是什么以及它们如何工作
instant appsby Tomislav Smrečki通过TomislavSmrečki Android Instant Apps are a cool new way to consume native apps without prior installation. Only parts of the app are downloaded and launched, giving the users a native look and feel in a couple of secon…

数据库分享一: MySQL的Innodb缓存相关优化
无论是对于哪一种数据库来说,缓存技术都是提高数据库性能的关键技术,物理磁盘的访问速度永 远都会与内存的访问速度永远都不是一个数量级的。通过缓存技术无论是在读还是写方面都可以大大提 高数据库整体性能。Innodb_buffer_pool_size 的合理设置Innodb…

用过美德乐吸奶器的宝妈们感觉比国产吸奶器怎么样啊?
药效好不好,看疗效就知道。吸奶器好不好看评价就知道。我们来看看美德乐吸奶器 天猫旗舰店 : http://medela.wang 的宝妈们的评价如可 拔奶神器,绝对好过贝亲!最初一次七八十,后来一百多,现在可以翻个倍。结合宝宝吮吸…

小程序地图多个 circles 使用demo
效果图: 代码: var that; const app getApp() const util require("../../utils/util.js") const data require("../../utils/map.js") Page({data: {pageShow: false,scale: 15,obj: {},longitude: 116.34665554470486,latitud…

编写文档_如何通过编写优质文档来使自己的未来快乐
编写文档by Gabriele Cimato加布里埃莱西马托(Gabriele Cimato) 如何通过编写优质文档来使自己的未来快乐 (How to make your future self happy by writing good docs) 或者,在清除旧代码库时如何减少痛苦 (Or how to be less miserable when dusting off an old …

(转载)人人都会OSGI--实例讲解OSGI开发
http://longdick.iteye.com/blog/457310转载于:https://www.cnblogs.com/eecs2016/articles/7422310.html

小程序json字符串转 json对象 { name :你好} 转成 { name :你好}
解决后端接口返回 var obj "{ name :"你好"}" 类似这样的数据,对象或者数组外面包了一层引号, 把这种数据转成 var obj { name :"你好"}; 直接上代码: // pages/test/test.js Page({jsonStrToJ…

每天写的叫工作日志,每周写的总结叫周报,每月写的叫月报
有些时候,老板会突发让您求每天都要写工作周报,什么项目什么任务,完成情况,完成花费的时间等,然后汇总部门周报;也不是写不出,只是不知道有时候重复做一个项目,到底每天有什么好写&a…

为什么分散刷新没有死时间_分散项目为何失败(以及如何处理)
为什么分散刷新没有死时间The most exciting thing about working in the decentralized economy is the fact that no one has any idea as to where it’ll all end up!在去中心decentralized economy工作最令人振奋的事情是,没有人知道最终的结果! T…

.NET Core 常用加密和Hash工具NETCore.Encrypt
前言 在日常开发过程中,不可避免的涉及到数据加密解密(Hash)操作,所以就有想法开发通用工具,NETCore.Encrypt就诞生了。目前NETCore.Encrypt只支持.NET Core ,工具包含了AES,DES,RSA加密解密,MD5࿰…

url 通配符解析成参数
需求:url 参数是通配符,需要把通配符解析成参数并且拼接到 url 中 例如:https://xxx.cn/index.html$a1$b2; 解析成 https://xxx.cn/index.html?a1&b2; 时间关系,直接上代码,有时间再补上注释 下面是小程序页…

性能测试分享:系统架构
性能测试分享:系统架构 转载于:https://www.cnblogs.com/poptest/p/4904584.html

graphql是什么_为什么GraphQL是避免技术债务的关键
graphql是什么GraphQL (not to be confused with GraphDB or Open Graph or even an actual graph) is a remarkably creative solution to a relatively common problem: How do you enable front end developers to access backend data in exactly the way they need it?Gr…

JS如何判断json是否为空
1、判断json是否为空 jQuery.isEmptyObject(); 2、遍历json function getHsonLength(json{var jsonLength0;for (var i in json){jsonLength;}return jsonLength;}转载于:https://www.cnblogs.com/donaldworld/p/7423811.html

微软算法100题11 求二叉树中两节点之间的最大距离
第11 题求二叉树中节点的最大距离...如果我们把二叉树看成一个图,父子节点之间的连线看成是双向的,我们姑且定义"距离"为两节点之间边的个数。写一个程序,求一棵二叉树中相距最远的两个节点之间的距离 思路: 一棵树中节点的最大距…

小程序订阅消息 订阅消息开发
微信小程序交流QQ群: 173683895 173683866 526474645 。 群内打广告或者脏话一律飞机票 订阅消息 当用户勾选了订阅面板中的“总是保持以上选择,不再询问”时,模板消息会被添加到用户的小程序设置页,通过 wx.getSetting…

meetup_如何使用标准库和Node.js构建Meetup Slack机器人
meetupby Janeth Ledezma简妮丝莱德兹玛(Janeth Ledezma) 如何使用标准库和Node.js构建Meetup Slack机器人 (How to build a Meetup Slack bot with Standard Library and Node.js) In this guide, you will learn how to set up a Slack application that will display infor…

.NET使用OpenSSL生成的pem密钥文件[1024位]
using System; using System.Text; using System.Security.Cryptography; using System.Web; using System.IO;namespace Thinhunan.Cnblogs.Com.RSAUtility {public class PemConverter{/// <summary>/// 将pem格式公钥转换为RSAParameters/// </summary>/// <…

[2014百度之星资格赛]
第一个问题: Energy Conversion Problem Description魔法师百小度也有遇到难题的时候——如今。百小度正在一个古老的石门面前,石门上有一段古老的魔法文字,读懂这样的魔法文字须要耗费大量的能量和大量的脑力。过了许久。百小度最终读懂魔法…

视频录制,压缩实现源码
实现代码: <!DOCTYPE html> <html><head><meta charset"utf-8"><title></title><meta name"viewport" content"widthdevice-width, initial-scale1.0"><!-- <script src"./js…

alexa技能个数_如何在您的技能中使用Alexa演示语言
alexa技能个数by Garrett Vargas通过Garrett Vargas 如何在您的技能中使用Alexa演示语言 (How to use Alexa Presentation Language in your skill) Amazon recently released the Alexa Presentation Language (APL). APL provides a richer display for multimodal skills. …

HTML与XML总结
阅览《孙欣HTML》和《刘炜XML》过了一段时间,在这里学到的内容用思维导图来概括。HTML与XML都是标记语言。 同样点: HTML文档与XML文档有类似的结构。前者是(head和body)后者是(声明和主体),大致…

ant PageHeaderWrapper 返回上一页
PageHeaderWrapper 返回上一页实现代码: <PageHeaderWrappertitle{false}content{<a onClick{() > router.goBack()}><Icon type"left" />返回</a>}breadcrumb{{routes: [{ path: /, breadcrumbName: 首页 },{ path: /pay_orde…

ruby 新建对象_Ruby面向对象编程的简介
ruby 新建对象by Saul Costa由Saul Costa Object-oriented programming (OOP) is a programming paradigm organized around objects. At a high level, OOP is all about being able to structure code so that its functionality can be shared throughout the application.…

ASP.NET导出文件FileResult的使用
本文给大家讲一下ASP.NET MVC中如何使用FileResult来导出文件,首先网上相关例子有很多大神都有讲,我在这只是稍微说一点不同——为什么我的导出没有反应呢? 这个问题,我找了半天也没有找到,最后是在一个网友的评论中体…