专栏名称: 3033
iOS开发
目录
相关文章推荐
科幻世界SFW  ·  新刊速递 | ... ·  2 天前  
四川省广播电视局  ·  壹同制作入驻成都影视城签约仪式暨科幻题材电视 ... ·  3 天前  
51好读  ›  专栏  ›  3033

iOS百度地图路径规划和POI检索详细总结

3033  · 掘金  ·  · 2017-12-14 00:35

正文

请到「今天看啥」查看全文



    [_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






请到「今天看啥」查看全文