<! DOCTYPE html>Baidu Map API Features
Add a map type control var map = new Bmap.map ("Allmap"); Map.centerandzoom (New Bmap.point (Lon,lat), 15); Added scale var Top_left_control = new Bmap.scalecontrol ({anchor:bmap_anchor_top_left});//upper left corner, add scale var Top_left_navigati on = new Bmap.navigationcontrol (); Upper left corner, add default zoom translation control var top_right_navigation = new Bmap.navigationcontrol ({anchor:bmap_anchor_top_right, TYPE:BMAP_ Navigation_control_small}); upper right corner Map.addcontrol (Top_left_control); Increase scale Map.addcontrol (top_left_navigation); Map.addcontrol (top_right_navigation);
var myP1 = new Bmap.point (Lon,lat); Starting point var myP2 = new Bmap.point (Mylon,mylat); End point var Myicon = new Bmap.icon ("Http://lbsyun.baidu.com/jsdemo/img/Mario.png", New Bmap.size (32, 70), {//Trolley pictures Offset:new bmap.size (0,-5),//corresponds to the offset of the CSS sprite Imageoffset:new bmap.size (0, 0)//Picture. In order to align the coordinates at the bottom center of the picture. }); var driving2 = new Bmap.drivingroute (map, {renderoptions:{map:map, autoviewport:true}}); Driving example Driving2.search (myP1, myP2); Show a bus line
Window.run = function () {var driving = new Bmap.drivingroute (map);//Driving Example Driving.search (myP1, myP2); Driving.setsearchcompletecallback (function () {var pts = Driving.getresults (). Getplan (0). Getroute (0). GetPath ( ); By driving the example, get a series of points of the array var paths = Pts.length; Get a few points
var carMk = new BMap.Marker (Pts[0],{icon: Myicon}); map.addoverlay (carMk); i=0; function Resetmkpoint (i) { carmk.setposition (Pts[i]); if (i < paths) { settimeout (Function ( ) { i++; &nBsp; resetmkpoint (i); &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;},60); } } settimeout (function () { resetmkpoint (5); }, 100)
}); }
SetTimeout (function () {run (); },1500);</script>
Baidu Map API Route simulation