Baidu Map API: Customize navigation through multiple points

Source: Internet
Author: User
Tags polyline

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:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.