1#import <Foundation/Foundation.h>
2#import <NavigineSDK/NavigineSDK.h>
19- (void)demonstrateRoutePathUsage:(
NCRoutePath *)routePath;
20- (void)demonstrateRouteNodeUsage:(
NCRouteNode *)node;
24- (void)demonstrateTurnEventUsage:(
NCTurnEvent *)event;
29- (void)demonstratePointUsage:(
NCPoint *)point;
31- (void)demonstrateAdvancedAsyncRoutingFeatures;
38@implementation AsyncRouteManagerExample
82 NSLog(
@"LocationManager, NavigationManager and AsyncRouteManager successfully initialized");
84 }
@catch (NSException *exception) {
85 NSLog(
@"Error initializing SDK: %@", exception.reason);
102 NSLog(
@"AsyncRouteManager not initialized");
107 NCPoint *destinationPoint = [[
NCPoint alloc] initWithX:100.0 y:100.0];
116 NSLog(
@"Created route session with default graph tag");
122 NSLog(
@"Created route session with 'main' graph tag");
126 self.currentSession = session;
139 if (routePath == nil) {
140 NSLog(
@"RoutePath is null");
147 NSLog(
@"Route length: %f meters", length);
153 NSLog(
@"Route weight: %f", weight);
158 NSArray<NCRouteNode *> *nodes = [
routePath getNodes];
159 NSLog(
@"Number of route nodes: %lu", (
unsigned long)nodes.count);
160 for (
int i = 0; i < nodes.count && i < 3; i++) {
169 NSLog(
@"Route head length: %f meters", [head getLength]);
177 NSLog(
@"Route tail length: %f meters", [tail getLength]);
189 float weight = [
node getWeight];
190 NSLog(
@"Node weight: %f", weight);
194 float distance = [
node getDistance];
195 NSLog(
@"Node distance: %f meters", distance);
199 NSArray<NCRouteEvent *> *events = [
node getEvents];
211 NSLog(
@"RouteEvent is null");
218 NSLog(
@"Event type: %ld", (
long)type);
223 if (turnEvent != nil) {
230 if (entryEvent != nil) {
237 if (exitEvent != nil) {
244 if (targetEvent != nil) {
256 NSArray<NSNumber *> *types = @[
262 NSLog(
@"Available route event types:");
263 for (NSNumber *type in types) {
264 NSLog(
@" - %ld", (
long)[type integerValue]);
271 NSArray<NSNumber *> *types = @[
280 for (NSNumber *type in types) {
281 NSLog(
@" - %ld", (
long)[type integerValue]);
289 NSLog(
@"Turn type: %ld", (
long)type);
293 int32_t angle = [
event getAngle];
294 NSLog(
@"Turn angle: %d", angle);
300 int64_t from = [
event getFrom];
301 NSLog(
@"Transition entry from: %lld", from);
305 int64_t to = [
event getTo];
306 NSLog(
@"Transition entry to: %lld", to);
312 int64_t from = [
event getFrom];
313 NSLog(
@"Transition exit from: %lld", from);
317 int64_t to = [
event getTo];
318 NSLog(
@"Transition exit to: %lld", to);
324 int64_t index = [
event getIndex];
325 NSLog(
@"Reached target index: %lld", index);
338 if (locationPoint == nil) {
339 NSLog(
@"LocationPoint is null");
346 NSLog(
@"Location point: (%f, %f)", [point getX], [point getY]);
352 NSLog(
@"Location ID: %d", locationId);
358 NSLog(
@"Sublocation ID: %d", sublocationId);
365 NSLog(
@"Created new location point: %f, %f", [[newLocationPoint getPoint] getX], [[newLocationPoint getPoint] getY]);
372- (void)demonstratePointUsage:(
NCPoint *)point {
374 NSLog(
@"Point is null");
380 double x = [
point getX];
381 NSLog(
@"Point X: %f", x);
386 double y = [
point getY];
387 NSLog(
@"Point Y: %f", y);
393 NSLog(
@"Created new point: (%f, %f)", [newPoint getX], [newPoint getY]);
401 NSLog(
@"=== Route Options ===");
406 NSLog(
@"Created route options with smoothRadius: %f, maxProjectionDistance: %f, maxAdvance: %f",
407 [routeOptions getSmoothRadius], [routeOptions getMaxProjectionDistance], [routeOptions getMaxAdvance]);
411 NSArray<NCRouteOptions *> *optionsList = @[
412 [[
NCRouteOptions alloc] initWithSmoothRadius:0.0 maxProjectionDistance:5.0 maxAdvance:2.0],
413 [[
NCRouteOptions alloc] initWithSmoothRadius:2.0 maxProjectionDistance:10.0 maxAdvance:1.0],
414 [[
NCRouteOptions alloc] initWithSmoothRadius:1.0 maxProjectionDistance:3.0 maxAdvance:3.0],
417 for (
int i = 0; i < optionsList.count; i++) {
419 NSLog(
@"Options %d: smoothRadius=%f, maxProjectionDistance=%f, maxAdvance=%f",
420 i + 1, [options getSmoothRadius], [options getMaxProjectionDistance], [options getMaxAdvance]);
427- (void)demonstrateAdvancedAsyncRoutingFeatures {
428 NSLog(
@"=== Advanced Async Routing Features ===");
435 NSArray<NCLocationPoint *> *destinations = @[
436 [[
NCLocationPoint alloc] initWithPoint:[[
NCPoint alloc] initWithX:50.0 y:50.0] locationId:12345 sublocationId:1],
437 [[
NCLocationPoint alloc] initWithPoint:[[
NCPoint alloc] initWithX:100.0 y:100.0] locationId:12345 sublocationId:1],
438 [[
NCLocationPoint alloc] initWithPoint:[[
NCPoint alloc] initWithX:150.0 y:150.0] locationId:12345 sublocationId:1]
442 NSArray<NCRouteOptions *> *optionsList = @[
443 [[
NCRouteOptions alloc] initWithSmoothRadius:2.0 maxProjectionDistance:5.0 maxAdvance:2.0],
444 [[
NCRouteOptions alloc] initWithSmoothRadius:3.0 maxProjectionDistance:7.0 maxAdvance:1.5],
445 [[
NCRouteOptions alloc] initWithSmoothRadius:1.0 maxProjectionDistance:3.0 maxAdvance:2.5],
449 NSMutableArray<NCRouteSession *> *sessions = [NSMutableArray array];
450 for (
int i = 0; i < destinations.count; i++) {
451 NCRouteSession *session = [
self.asyncRouteManager createRouteSession:destinations[i] routeOptions:optionsList[i]];
452 [sessions addObject:session];
453 NSLog(
@"Created session %d for destination: %f, %f",
454 i + 1, [destinations[i].getPoint getX], [destinations[i].getPoint getY]);
458 [NSThread sleepForTimeInterval:1.0];
462 [NSThread sleepForTimeInterval:3.0];
465 for (
int i = 0; i < sessions.count; i++) {
468 [
self.asyncRouteManager cancelRouteSession:sessions[i]];
469 NSLog(
@"Cancelled session %d", i + 1);
472 [NSThread sleepForTimeInterval:1.0];
480 NSLog(
@"=== RouteStatus Enum Usage ===");
484 NSLog(
@"Available RouteStatus values:");
485 NSArray *allStatuses = @[@(NCRouteStatusMissingGraph), @(NCRouteStatusMissingPosition), @(NCRouteStatusMissingRoute), @(NCRouteStatusMissingProjection), @(NCRouteStatusNewRoute)];
486 for (NSNumber *statusNumber in allStatuses) {
488 NSLog(
@" - %@: %@", @(status), @(status));
493 switch (testStatus) {
495 NSLog(
@"Router is ready for navigation");
498 NSLog(
@"Router is missing the route graph");
501 NSLog(
@"Router is missing the current position");
504 NSLog(
@"Current position is off the route graph");
507 NSLog(
@"Router unable to find the route to the destination point");
517 NSLog(
@"=== Route Session Management ===");
524 NCPoint *destinationPoint = [[
NCPoint alloc] initWithX:75.0 y:75.0];
530 NSLog(
@"Created session with default tag");
534 NSLog(
@"Created session with 'elevator' tag");
541 dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
547 NSLog(
@"Removed listeners from sessions");
553 NSLog(
@"Cancelled both sessions");
580 NSLog(
@"=== AsyncRouteManager Example ===");
582 [
self demonstrateAsyncRouteManagerMethods];
583 [
self demonstrateRouteEventTypes];
584 [
self demonstrateTurnTypes];
585 [
self demonstrateRouteOptions];
586 [
self demonstrateRouteStatusUsage];
587 [
self demonstrateRouteSessionManagement];
588 [
self demonstrateAdvancedAsyncRoutingFeatures];
591 [NSThread sleepForTimeInterval:3.0];
594 NSLog(
@"=== Example completed ===");
597#pragma mark - NCAsyncRouteListener
600- (void)onRouteChanged:(
NCRouteStatus)status currentPath:(NCRoutePath *)currentPath {
601 NSLog(
@"Route changed with status: %@", @(status));
603 [
self demonstrateRoutePathUsage:currentPath];
605 NSLog(
@"Route not ready, status: %@", @(status));
611- (void)onRouteAdvanced:(
float)distance point:(NCLocationPoint *)point {
612 NSLog(
@"Route advanced: %f meters", distance);
613 [
self demonstrateLocationPointUsage:point];
622int main(
int argc,
const char * argv[]) {
625 [example runExample];