iOS百度地图SDK记录

基础地图

导航

  • 使用集成的百度导航sdk,在不设置这个参数为YES。[BNCoreServices_RoutePlan setDisableOpenUrl:YES];,同时真机安装了百度地图的情况下,只能跳转到百度地图应用中。
    完整的路径规划代码如下:

    //关闭跳转百度地图功能,如果不关闭 在安装了百度地图的情况下只能使用百  度地图跳转
    [BNCoreServices_RoutePlan setDisableOpenUrl:YES];
    //发起路径规划
    [BNCoreServices_RoutePlan startNaviRoutePlan:BNRoutePlanMode_Recommend naviNodes:nodesArray time:nil delegete:self userInfo:nil];
    

自己的APP跳转到百度地图进行导航

  • 先判断是否安装了百度地图

    BOOL isInstallBaidu = [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"baidumap://"]];
    返回值为YES证明安装了百度地图
    
  • 根据参数组成协议url

    NSString *url =  [[NSString stringWithFormat:@"baidumap://map/direction?origin=latlng:%f,%f|name:我的位置&destination=latlng:%f,%f|name:%@&mode=driving",driverLocation.coordinate.latitude, driverLocation.coordinate.longitude,_locationModel.pt.latitude,_locationModel.pt.longitude,_locationModel.name] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    参数从前到后分别代表:起点纬度,起点经度,目的地纬度,目的地经度,目的地名称描述
    
  • openurl 进行跳转

    BOOL flage = [[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];
      if (!flage) {
          [self showHudErrorAutoDismiss:@"百度地图打开失败!"];
      }
    

你可能感兴趣的:(iOS百度地图SDK记录)