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