<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
<title>货车路线规划-使用经纬度</title>
<script type="text/javascript" src='https://webapi.amap.com/maps?v=1.4.15&key=你的高德地图key&plugin=AMap.TruckDriving'></script>
<style>
html,
body,
#container {
width: 100%;
height: 100%;
}
#panel {
position: fixed;
background-color: white;
max-height: 90%;
overflow-y: auto;
top: 10px;
right: 10px;
width: 280px;
}
#panel .amap-lib-driving {
border-radius: 4px;
overflow: hidden;
}
</style>
<link rel="stylesheet" href="https://a.amap.com/jsapi_demos/static/demo-center/css/demo-center.css" />
<script src="https://a.amap.com/jsapi_demos/static/demo-center/js/demoutils.js"></script>
</head>
<body>
<div id="container"></div>
<div id="panel"></div>
</div>
<script type="text/javascript">
var map = new AMap.Map("container", {});
var truckOptions = {
map: map,
policy:0,
size:1,
city:'shenzhen',
panel:'panel'
};
var driving = new AMap.TruckDriving(truckOptions);
var path = [
{keyword:'深圳站',city:'030'},//起点['keyword'=>地理位置,city=>精度,数值越小查询范围越小]如果查询不到路线可调整city数值大小
// {keyword:'北京西站',city:'010'},//途径
{keyword:'深圳北站',city:'030'}//终点
];
driving.search(path, function(status, result) {
console.log(result.routes[0].distance)//距离
// result即是对应的货车导航信息,相关数据结构文档请参考 https://lbs.amap.com/api/javascript-api/reference/route-search#m_DrivingResult
if (status === 'complete') {
log.success('绘制货车路线完成')
} else {
log.error('获取货车规划数据失败:' + result)
}
});
</script>
</body>
</html>