正文
[_mapView removeOverlays:_mapView.overlays];
NSArray *annArray = [[NSArray alloc]initWithArray:_mapView.annotations];
[_mapView removeAnnotations: annArray];
之后我们创建路径规划的方法
_searcher = [[BMKRouteSearch alloc]init];
_searcher.delegate = self;
//发起检索
BMKPlanNode* start = [[BMKPlanNode alloc]init] ;
start.name = _startFiled.text;
BMKPlanNode* end = [[BMKPlanNode alloc]init];
end.name = _endFiled.text;
start.cityName = self.city;
end.cityName = self.city;
BMKDrivingRoutePlanOption *driveRouteSearchOption =[[BMKDrivingRoutePlanOption alloc]init];
driveRouteSearchOption.from = start;
driveRouteSearchOption.to = end;
这里要注意的就是因为我们是驾车路径规划,所以创建的是BMKDrivingRoutePlanOption,我们进入到内部方法可以看到,入过我们是公交和步行对应的则是他们各自的Option,发起检索成功后会调取他的协议方法,这里的前提是要遵循BMKRouteSearchDelegate协议
- (void)onGetDrivingRouteResult:(BMKRouteSearch*)searcher result:(BMKDrivingRouteResult*)result errorCode:(BMKSearchErrorCode)error
在上述的协议方法中,我们设置起点,终点,以及路段入口信息和各轨迹点的总数
for (int i = 0; i < size; i++) {
BMKDrivingStep *tansitStep = [plan.steps objectAtIndex:i];
if (i == 0 ) {
BMKPointAnnotation* annotation = [[BMKPointAnnotation alloc]init];
annotation.coordinate = plan.terminal.location;
annotation.title = @"起点";
[_mapView addAnnotation:annotation];
} else if (i == size - 1) {
BMKPointAnnotation* annotation = [[BMKPointAnnotation alloc]init];
annotation.coordinate = plan.terminal.location;
annotation.title = @"终点";
[_mapView addAnnotation:annotation];
}
BMKPointAnnotation* annotation = [[BMKPointAnnotation alloc]init];
annotation.coordinate = tansitStep.entrace.location; //路段入口信息
annotation.title = tansitStep.instruction; //路程换成说明
[_mapView addAnnotation:annotation];
//轨迹点总数累计
planPointCounts += tansitStep.pointsCount;
}
//轨迹点
BMKMapPoint * temppoints = new BMKMapPoint[planPointCounts]; //文件后缀名改为mm
int i = 0;
for