轨迹纠偏 最后更新时间: 2021年01月22日
轨迹纠偏服务插件。用于将一组带方向的、可能偏离道路的经纬度轨迹,纠正为准确沿着道路的一条经纬度路径。比如将一组间隔采集的车辆位置和朝向、速度、时间等信息传入,可以得到一组沿着道路行进的经纬度路径和总的行驶历程。
准备原始轨迹数据
纠偏之前需要按照下面的数据规格准备原始轨迹点,x、y、sp、ag、tm
分别代表经度、纬度、速度、角度、时间。
需要注意:
1. 经纬度应该是高德坐标,而不是GPS直接采集的坐标,可通过AMap.convertFrom转化
2. tm以秒为单位,第一个采集点的tm值从1970年0点开始,其他采集点为与第一个采集点时间的差值
var originPath= [
{"x":116.478928,"y":39.997761,"sp":19,"ag":0, "tm":1478031031},
{"x":116.478907,"y":39.998422,"sp":10,"ag":0, "tm":2},
{"x":116.479384,"y":39.998546,"sp":10,"ag":110,"tm":3},
{"x":116.481053,"y":39.998204,"sp":10,"ag":120,"tm":4},
{"x":116.481793,"y":39.997868,"sp":10,"ag":120,"tm":5},
{"x":116.482898,"y":39.998217,"sp":10,"ag":30, "tm":6},
{"x":116.483789,"y":39.999063,"sp":10,"ag":30, "tm":7},
{"x":116.484674,"y":39.999844,"sp":10,"ag":30, "tm":8}]
调用轨迹纠偏服务
AMap.plugin('AMap.GraspRoad',function(){
var grasp = new AMap.GraspRoad();
grasp.driving(originPath,function(error,result){
if(!error){
var newPath = result.data.points;//纠偏后的轨迹
var distance = result.data.distance;//里程
}
})
})