There is a limit to the number of navigation points that Baidu officially provides to developers: no more than 10 passes. Suppose I have n points in my hand to draw a trajectory, what to do. However, the route for each point and the next point must be Baidu's recommended route.
1, define the driving object: **onsearchcomplete** function can get every driving.search retrieval after the completion of the callback function, where you can get a collection of points to draw
var driving = new Bmap.drivingroute (map, {onsearchcomplete:function (results) {
if (driving.getstatus () = = Bmap_ status_success) {
var plan = Driving.getresults (). Getplan (0);
var num = plan.getnumroutes ();
Alert ("Plan.num:" +num);
for (Var j =0;j<num; J + +) {
//by driving an instance, get a series of points of the array
var pts= plan.getroute (J). GetPath ();
var polyline = new Bmap.polyline (pts);
Map.addoverlay (polyline); Draw track
}}}
);
2. Search parameters: <=10 of multiple passing points. Tip: Do a search between every 11 points, and then search directly at less than 11 points at a time
var group = Math.floor (POINTLIST.LENGTH/11);
var mode = Pointlist.length%11;
if (mode! = 0) {
var waypoints=pointlist.slice (group*11,pointlist.length-1);//The extra section is a separate search Driving.search (Pointlist[group*11],pointlist[pointlist.length-1],{waypoints:waypoints});}
for (var i =0;i<group;i++) {
var waypoints = Pointlist.slice (i*11+1, (i+1) *11); Driving.search (pointlist[i*11), pointlist[(i+1) *11],{waypoints:waypoints});//waypoints means through point
}
Custom 28 Baidu Point coordinate object, call the above method, the effect diagram is as follows:
The complete code is as follows: