ycvcb123 / run:记录运行轨迹,事物

2020-12-15
来源:

地图中的标记是一个数组。根据此对象数组每个元素的坐标,运动轨迹将绘制在地图上。 iconpath是代表当前位置的图标。

注意:

在用标记替换封面后,必须添加width和height属性! ! !否则,您将看不到该图标。


markers: [{     iconPath: "/resources/others.png",     id: 0,     latitude: 23.099994,     longitude: 113.324520,     width: 50,     height: 50   }]

微信小程序开发记录运动轨迹

基于两个点的纬度和经度计算距离的代码如下,直接复制即可,不明白,我也是在线找到的。


function toRadians(d) { return d * Math.PI / 180; }var dis = 0;var radLat1 = toRadians(lat1);var radLat2 = toRadians(lat2);var deltaLat = radLat1 - radLat2;var deltaLng = toRadians(lon1) - toRadians(lon2);var dis = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(deltaLat / 2), 2) + Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(deltaLng / 2), 2)));//6378137 地球半径return dis * 6378137;

如何记录轨迹,时间和距离?

递归调用如下:


keepPaint: function () {     var that = this;     if (starRun == 0) {         return;     }     if (countTooGetLocation >= 100) {         var time = that.date_format(total_micro_second);         that.updateTime(time);     }     if (countTooGetLocation >= 5000) { //1000为1s         that.getLocation();         countTooGetLocation = 0;     }     setTimeout(function () {         countTooGetLocation += 10;         total_micro_second += 10;         that.keepPaint(that);     }, 10)}

分享