外部文件引入
<script type="text/javascript" src="https://webapi.amap.com/maps?v=1.4.15&key=您申请的key值"></script> <script type="text/javascript" src="https://cache.amap.com/lbs/static/addToolbar.js"></script>
构建地图
var map, route, marker; //基本地图加载 map = new AMap.Map("container", { resizeEnable: true }); //绘制初始路径 var path = []; path.push([121.608693,29.913687]); path.push([121.615324,29.914654]); path.push([121.612749,29.916198]); map.plugin("AMap.DragRoute", function() { route = new AMap.DragRoute(map, path, AMap.DrivingPolicy.LEAST_FEE); //构造拖拽导航类 route.search(); //查询导航路径并开启拖拽导航 route.on('complete', function() { console.log(route.getRoute()); }) });
lockdatav Done!