IOS Baidu Map track record road fit

Source: Internet
Author: User

Recently in a small demo, try the track record.

Record tracks need to keep getting location records to the database.

When the picture is folded, it will be connected directly at the corner of the road, and will not fit the road, and here is my solution.

I called the path planning API for Baidu maps. This will enable the path fit function.

Attach dome here: Click to open link

Stress: This dome is a real-world operation and will be an error on the simulator. Please pay attention when downloading.

For various reasons the picture is taken with a mobile phone.

Take a look at the picture above:



Core code:

Call the drive route plan, plan the line from this point to that and draw the route, and the resulting line is obtained in the following function.

-(void) Ongetdrivingrouteresult: (Bmkroutesearch *) Searcher Result: (Bmkdrivingrouteresult *) result ErrorCode: ( Bmksearcherrorcode) Error
above this is the proxy method.

Bmkplannode *startnode = [[Bmkplannode alloc]init];    Cllocationcoordinate2d startcoordinate;    Startcoordinate.latitude =36.727558;    Startcoordinate.longitude =119.185956;    startnode.pt = startcoordinate;    Bmkplannode *endnode = [[Bmkplannode alloc]init];    Cllocationcoordinate2d endcoordnate;    Endcoordnate.latitude =36.827558;    Endcoordnate.longitude =119.385956;    endnode.pt = endcoordnate;    Bmkdrivingrouteplanoption * drivingrouteplanoption = [[Bmkdrivingrouteplanoption alloc]init];    Drivingrouteplanoption.from = Startnode;    drivingrouteplanoption.to = Endnode;    if ([_searcher drivingsearch:drivingrouteplanoption]) {        NSLog (@ "Route lookup succeeded");    }

-(void) Ongetdrivingrouteresult: (Bmkroutesearch *) Searcher Result: (Bmkdrivingrouteresult *) result ErrorCode: (    Bmksearcherrorcode) error{bmkdrivingrouteline *plan = (Bmkdrivingrouteline *) [result.routes objectAtIndex:0];    int size = (int) [Plan.steps count];    int pointcount = 0;        for (int i = 0; i< size; i++) {Bmkdrivingstep *step = [Plan.steps objectatindex:i];    Pointcount + = Step.pointscount;    } bmkmappoint *points = new Bmkmappoint[pointcount];    int k = 0;        for (int i = 0; i< size; i++) {Bmkdrivingstep *step = [Plan.steps objectatindex:i];            for (int j= 0; j<step.pointscount; j + +) {points[k].x = step.points[j].x;            Points[k].y = STEP.POINTS[J].Y;        k++;    }} NSLog (@ "Number of points: (%d)", k);    Bmkpolyline *polyline = [Bmkpolyline polylinewithpoints:points count:pointcount]; [_mapview addoverlay:polyline];}
In the above method we get the route from the returned line, then get the points from the road segment, and finally draw the line.

IOS Baidu Map track record road fit

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.