1,引入高德地图;
<script src="https://webapi.amap.com/maps?v=1.4.15&key=你申请的key"></script>
2,初始化高德地图;
new AMap.Map('allMap', {
resizeEnable: true,
zoom: 13,
center: [116.404, 39.915],
});
3,加载货车插件;
let path = [];
path.push({lnglat: [116.303843, 39.983412] });
path.push({lnglat: [116.321354, 39.896436]});
path.push({lnglat: [116.397428, 39.90923]});
path.push({lnglat: [116.407012, 39.992093]});
const truckOptions = {
map,
policy: 1,
size: 1,
hideMarkers: false,
autoFitView: true,
};
AMap.plugin('AMap.TruckDriving', () => {
const trunkDriving = new AMap.TruckDriving(truckOptions);
if (path[0]) {
trunkDriving.search(path, (status, result) => {
if (status === 'complete') {
console.log('success');
} else {
console.log(`error-${result}`);
}
});
}
});