Live Navigation
Real-time navigation, also known as GPS navigation, is a navigation that is driven by continuous GPS positioning information for the actual navigation process. After the route is successfully planned (driving or walking), you can start navigating. The sample code is as follows:
(For complete code, see MBNaviController.m in the SDKDemo project) // real-time navigation if (naviMapView == nil) { // Map does not exist naviMapView=[[MBMapView alloc]initWithFrame:(0,120.0,kMainScreenSizeWidth, kMainScreenSizeHeight - 120.0 - 55.0)]; [self.view addSubview:naviMapView]; // Create a car logo layer MBModelOverlay *car = [[MBModelOverlay alloc] initWithFilePath:@"res/red_car.obj"]; carHead = MBNaviHeadNorthUp; } // Initialize the navigation module MBNaviSession *naviSession = [MBNaviSession sharedInstance]; naviSession.enableSound = YES; naviSession.delegate = self; // Callback function completed by route calculation - (void)naviSessionResult:(MBRouteCollection *)routes { // Calculate the road to complete // Get the routes collection, the routeBases in this collection, need to use when initiating navigation to obtain data 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]; } } } - (void)naviSessionTracking:(MBNaviSessionData *)sData { NSLog (@"current car location: %d, %d", sData.carPos.x, sData.carPos.y); NSLog (@"current head orientation: %ld", (long) sData.carOri); NSLog (@"current recommended scale: %ld", (long) sData.suggestedMapScale); NSLog (@" Is there a next turn: %@, and %ld meters turn", sData.hasTurn?@"Yes": @"No", (long)sData.turnIconDistance); NSLog(@"current steering ID: %ld", (long)sData.turnIcon); NSLog (@"Road name after turn: %@", sData.nextRoadName); NSLog (@"current road name: %@", sData.roadName); NSLog(@"\n"); }