Simulated Navigation
Analog navigation, used only for indoor simulations, to help you understand some of the conditions of a given route in advance.
The implementation method of simulated navigation is basically the same as real-time navigation. The difference is that the path planning successfully calls the startSimulation method after obtaining the current planned route.
(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];
}
}
[naviSession startSimulation];
}
- (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");
}
