您现在的位置:
概述
四维地图导航客户端应用产品开发SDK【Navinfo Navigation SDK for iOS】是一套基于iOS 8.0版本及以上操作系统的地图导航客户端应用产品开发工具包。用户可以轻松构造地图导航基础上的各种交互式应用产品。四维地图导航客户端应用产品开发SDK提供了3D地图显示与操作、位置信息搜索、导航算路、导航过程管理等基本功能,满足不同用户的各种应用需求。
功能介绍与体验
-
模拟导航
(完整代码详见 SDKDemo 工程的 MBNaviController.m) // 实时导航 if (naviMapView == nil) { // 地图不存在 naviMapView=[[MBMapView alloc]initWithFrame:(0,120.0,kMainScreenSizeWidth, kMainScreenSizeHeight - 120.0 - 55.0)]; [self.view addSubview:naviMapView]; // 创建车标图层 MBModelOverlay *car = [[MBModelOverlay alloc] initWithFilePath:@"res/red_car.obj"]; carHead = MBNaviHeadNorthUp; } // 初始化导航模块 MBNaviSession *naviSession = [MBNaviSession sharedInstance]; naviSession.enableSound = YES; naviSession.delegate = self; // 路线计算完成的回调函数 - (void)naviSessionResult:(MBRouteCollection *)routes { // 算路完成 // 得到routes集合,此集合中的routeBases,在发起导航获取数据时需用到 for (MBOverlay *overlay in naviMapView.overlays) { [naviMapView removeOverlay:overlay]; } if (routes.routeBases.count > 0) { MBRouteOverlay *routeOverlay = nil; for (MBRouteBase *base in routes.routeBases) { routeOverlay = [[MBRouteOverlay alloc] initWithRoute:base.getRouteBase]; routeOverlay.clickEnable = YES; [naviMapView addOverlay:routeOverlay]; } } [naviSession startSimulation]; } - (void)naviSessionTracking:(MBNaviSessionData *)sData { NSLog(@"当前车的位置:%d,%d",sData.carPos.x,sData.carPos.y); NSLog(@"当前车头朝向:%ld",(long)sData.carOri); NSLog(@"当前建议比例尺:%ld",(long)sData.suggestedMapScale); NSLog(@"是否有下一个转弯:%@,还有%ld米转弯",sData.hasTurn?@"是":@"没有",(long)sData.turnIconDistance); NSLog(@"当前转向标ID:%ld",(long)sData.turnIcon); NSLog(@"转弯之后的道路名称:%@",sData.nextRoadName); NSLog(@"当前所在道路名称:%@",sData.roadName); NSLog(@"\n"); }
-
HUD导航模式
- (void)updateHudViewWith:(MBNaviSessionData *)realtimeData { if (!realtimeData) { return; } MBNaviSessionData *aData = realtimeData; if (realtimeData.hasTurn) { _hudView.roadNameLabel.text = [NSString stringWithFormat:@"%@", aData.nextRoadName]; } if (!aData.drifting) { [_hudView.destanceProgressView setProgress: realtimeData.turnIconProgress/128.0 animated:YES]; }
NSInteger turnId = aData.turnIcon; MBGpsInfo *gpsInfo = [FakeGpsTracker sharedGpsTracker].currentGPSInfo;
if(!aData.drifting && turnId != 0 && gpsInfo.valid) { if(turnId == 1) { _hudView.turn_icon.hidden = YES; _hudView.turn_title.hidden = NO; _hudView.turn_icon_title.hidden = YES; } else { _hudView.turn_icon.image = [[MBResource sharedResoure] imageForName:[NSString stringWithFormat:@"turn_icons_hud/turn_hud_icons%ld.png", (long)turnId]]; _hudView.turn_icon.hidden = NO; _hudView.turn_title.hidden = YES; _hudView.turn_icon_title.hidden = YES; } } else { _hudView.turn_icon.hidden = YES; _hudView.turn_title.hidden = NO; _hudView.turn_icon_title.hidden = NO; } NSString*str = [MBUtils distanceTextWithLength:aData.turnIconDistance]; str = [str stringByReplacingOccurrencesOfString:@"米" withString:@" 米"]; if(aData.turnIconDistance >= 0) { NSMutableAttributedString *attrString = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@后进入",str]]; if (_hudView.layout == HUDViewLayoutHorizontal) { [attrString setAttributes:@{NSFontAttributeName: [UIFont mbMediumFont100]} range:NSMakeRange(0, attrString.length)]; [attrString setAttributes:@{NSFontAttributeName: [UIFont mbMediumFont56]} range:NSMakeRange(attrString.length - 5, 5)]; } else { [attrString setAttributes:@{NSFontAttributeName: [UIFont mbMediumFont160]} range:NSMakeRange(0, attrString.length)]; [attrString setAttributes:@{NSFontAttributeName: [UIFont mbMediumFont80]} range:NSMakeRange(attrString.length - 5, 5)]; } if ([attrString.string containsString:@" "]) { [attrString deleteCharactersInRange:NSMakeRange(attrString.length - 5, 1)]; } _hudView.destanceLabel.attributedText = attrString; } else { _hudView.destanceLabel.text = @""; } if(gpsInfo.valid) { NSMutableAttributedString *attrString = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%3.0f km/h",aData.speed*3.6]]; if (_hudView.layout == HUDViewLayoutHorizontal) { [attrString setAttributes:@{NSFontAttributeName: [UIFont mbMediumFont56]} range:NSMakeRange(0, attrString.length)]; [attrString setAttributes:@{NSFontAttributeName: [UIFont mbMediumFont40]} range:NSMakeRange(attrString.length - 4, 4)]; } else { [attrString setAttributes:@{NSFontAttributeName: [UIFont mbMediumFont80]} range:NSMakeRange(0, attrString.length)]; [attrString setAttributes:@{NSFontAttributeName: [UIFont mbMediumFont40]} range:NSMakeRange(attrString.length - 4, 4)]; } _hudView.speedLabel.attributedText = attrString; } else { _hudView.speedLabel.text = @"信号弱"; } const MBRoadCamera *camera = aData.firstCamera; NSInteger routeDistance = aData.routeLength - aData.travelledDistance; NSString *distanceStr = nil; if (routeDistance >= 1000) { distanceStr = [NSString stringWithFormat:@"剩余%.0f公里", round(routeDistance / 1000.0)]; } else { distanceStr = [NSString stringWithFormat:@"剩余%@", [MBUtils distanceTextWithLength:routeDistance]]; } NSString *timeStr = nil; NSInteger hours = aData.remainingTime / 3600; NSInteger minutes = aData.remainingTime / 60 - hours*60; if (minutes > 60) { timeStr = [NSString stringWithFormat:@"%ld小时%ld分钟",(long)hours,(long)minutes]; } else if (minutes == 60){ timeStr = [NSString stringWithFormat:@"%ld小时",(long)hours]; } else { timeStr = [NSString stringWithFormat:@"%ld分钟",(long)minutes]; } if (_hudView.layout == HUDViewLayoutHorizontal) { _hudView.all_destanceLabel.text = [NSString stringWithFormat:@"%@\n%@",distanceStr,timeStr]; } else { _hudView.all_destanceLabel.text = [NSString stringWithFormat:@"%@, %@",distanceStr,timeStr]; }
if(camera && (camera.type == MBCameraType_speed || camera.type == MBCameraType_radar || camera.type == MBCameraType_mobile)) { [_hudView.speed_icon setTitle:[NSString stringWithFormat:@"%lu",(unsigned long)camera.speedLimit] forState:0]; [_hudView.speedProgressView setProgress:(500 - camera.distanceFromCar)/500.0 animated:YES]; _hudView.speed_icon.hidden = NO; _hudView.compassLabel.hidden = YES; _hudView.speedProgressView.hidden = NO; } else { _hudView.speed_icon.hidden = YES; _hudView.speedProgressView.hidden = YES; _hudView.compassLabel.hidden = NO; _hudView.compassLabel.text = [self getCarOriStr:aData.carOri]; } }
- (NSString *)getCarOriStr:(NSUInteger)ori { NSUInteger n = ori/45; NSUInteger d = ori%45; NSArray *arr = @[@"东",@"东偏北",@"东北",@"北偏东",@"北",@"北偏西",@"西北",@"西偏北",@"西",@"西偏南",@"西南",@"南偏西",@"南",@"南偏东",@"东南",@"东偏南"]; // NSString *str = [NSString stringWithFormat:@"%@%@",[arr objectAtIndex:(2*n+(d?1:0))%16],d?[NSString stringWithFormat:@"%lu°", (long)(n%2?45-d:d)]:@""]; return [arr objectAtIndex:(2*n+(d?1:0))%16]; } -
多路线规划
(完整代码详见 SDKDemo 工程的 MBNavigationBaseController.m) // 路线查询方案 @property (nonatomic, strong) MBRoutePlan *routePlan; // 初始化MBRoutePlan _routePlan = [[MBRoutePlan alloc]init]; // 模拟起点 MBPoiFavorite *startPoint = [[MBPoiFavorite alloc]init]; MBPoint startPos = {11639061, 4001898}; startPoint.pos = *(&startPos); // 模拟终点 MBPoiFavorite *endPoint = [[MBPoiFavorite alloc]init]; MBPoint endPos = {11639743,3990885}; endPoint.pos = *(&endPos); // 设置起点 [_routePlan setStartPoint:startPoint]; // 设置终点 [_routePlan setEndPoint:endPoint]; // 设置算路规则 [_routePlan setRule:MBRouteRule_recommended]; // 开始算路 [naviSession startRoute:_routePlan routeMethod:MBNaviSessionRouteMethod_multipleResult]; // MBNaviSessionDelegate -(void)naviSessionRouteStarted{ // 开始算路 } -(void)naviSessionResult:(MBRouteCollection *)routes{ // 算路完成 // 得到routes集合,此集合中的routeBases,在发起导航获取数据时需用到 } - (void)naviSessionRouteFailed:(MBTRouterError)errCode moreDetails:(NSString*)details{ // 算路失败 }