1#import <Foundation/Foundation.h>
2#import <NavigineSDK/NavigineSDK.h>
10@property (nonatomic, strong) NCNavigineSdk *
sdk;
18- (void)demonstrateAsyncRouteManagerMethods;
19- (void)demonstrateRoutePathUsage:(NCRoutePath *)routePath;
20- (void)demonstrateRouteEventUsage:(NCRouteEvent *)event;
21- (void)demonstrateRouteEventTypes;
22- (void)demonstrateLocationPointUsage:(NCLocationPoint *)locationPoint;
23- (void)demonstratePointUsage:(NCPoint *)point;
24- (void)demonstrateRouteOptions;
25- (void)demonstrateAdvancedAsyncRoutingFeatures;
26- (void)demonstrateRouteSessionManagement;
32@implementation AsyncRouteManagerExample
52 [
self.sdk setUserHash:@"USER-HASH-HERE"];
57 [
self.sdk setServer:@"https://custom.navigine.com"];
62 self.locationManager = [
self.sdk getLocationManager];
67 self.navigationManager = [
self.sdk getNavigationManager:
self.locationManager];
72 self.asyncRouteManager = [
self.sdk getAsyncRouteManager:
self.locationManager navigationManager:
self.navigationManager];
76 NSLog(
@"LocationManager, NavigationManager and AsyncRouteManager successfully initialized");
78 }
@catch (NSException *exception) {
79 NSLog(
@"Error initializing SDK: %@", exception.reason);
94- (void)demonstrateAsyncRouteManagerMethods {
96 NSLog(
@"AsyncRouteManager not initialized");
101 NCPoint *destinationPoint = [[NCPoint alloc] initWithX:100.0 y:100.0];
102 NCLocationPoint *destinationLocationPoint = [[NCLocationPoint alloc] initWithPoint:destinationPoint locationId:12345 sublocationId:1];
105 NCRouteOptions *routeOptions = [[NCRouteOptions alloc] initWithSmoothRadius:2.0 maxProjectionDistance:5.0 maxAdvance:2.0];
109 NCRouteSession *session = [
self.asyncRouteManager createRouteSession:destinationLocationPoint routeOptions:routeOptions];
110 NSLog(
@"Created route session with default graph tag");
115 NCRouteSession *sessionWithTag = [
self.asyncRouteManager createRouteSessionWithTag:destinationLocationPoint routeOptions:routeOptions tag:@"main"];
116 NSLog(
@"Created route session with 'main' graph tag");
120 self.currentSession = session;
125 [session addRouteListener:
self];
132- (void)demonstrateRoutePathUsage:(NCRoutePath *)routePath {
133 if (routePath == nil) {
134 NSLog(
@"RoutePath is null");
141 NSLog(
@"Route length: %f meters", length);
146 NSArray<NCLocationPoint *> *points = [
routePath getPoints];
147 NSLog(
@"Number of route points: %lu", (
unsigned long)points.count);
148 for (
int i = 0; i < points.count && i < 3; i++) {
149 NSLog(
@"Point %d: %@", i + 1, points[i]);
155 NSArray<NCRouteEvent *> *events = [
routePath getEvents];
156 NSLog(
@"Number of route events: %lu", (
unsigned long)events.count);
157 for (
int i = 0; i < events.count && i < 3; i++) {
164 NCRoutePath *head = [
routePath head:10.0];
166 NSLog(
@"Route head length: %f meters", [head getLength]);
172 NCRoutePath *tail = [
routePath tail:10.0];
174 NSLog(
@"Route tail length: %f meters", [tail getLength]);
182- (void)demonstrateRouteEventUsage:(NCRouteEvent *)event {
184 NSLog(
@"RouteEvent is null");
190 NCRouteEventType type = [
event getType];
191 NSLog(
@"Event type: %ld", (
long)type);
196 int value = [
event getValue];
197 NSLog(
@"Event value: %d", value);
202 double distance = [
event getDistance];
203 NSLog(
@"Event distance: %f meters", distance);
208 NCRouteEvent *newEvent = [[
NCRouteEvent alloc] initWithType:NCRouteEventTypeTurnLeft value:90 distance:50.0];
209 NSLog(
@"Created new route event: %ld at %f meters", (
long)[newEvent getType], [newEvent getDistance]);
216- (void)demonstrateRouteEventTypes {
219 NSArray<NSNumber *> *types = @[
220 @(NCRouteEventTypeTurnLeft),
221 @(NCRouteEventTypeTurnRight),
222 @(NCRouteEventTypeTransition)
224 NSLog(
@"Available route event types:");
225 for (NSNumber *type in types) {
226 NSLog(
@" - %ld", (
long)[type integerValue]);
234- (void)demonstrateLocationPointUsage:(NCLocationPoint *)locationPoint {
235 if (locationPoint == nil) {
236 NSLog(
@"LocationPoint is null");
243 NSLog(
@"Location point: (%f, %f)", [point getX], [point getY]);
249 NSLog(
@"Location ID: %d", locationId);
255 NSLog(
@"Sublocation ID: %d", sublocationId);
260 NCPoint *newPoint = [[
NCPoint alloc] initWithX:25.0 y:35.0];
261 NCLocationPoint *newLocationPoint = [[
NCLocationPoint alloc] initWithPoint:newPoint locationId:12345 sublocationId:2];
262 NSLog(
@"Created new location point: %f, %f", [[newLocationPoint getPoint] getX], [[newLocationPoint getPoint] getY]);
269- (void)demonstratePointUsage:(NCPoint *)point {
271 NSLog(
@"Point is null");
277 double x = [
point getX];
278 NSLog(
@"Point X: %f", x);
283 double y = [
point getY];
284 NSLog(
@"Point Y: %f", y);
289 NCPoint *newPoint = [[
NCPoint alloc] initWithX:15.0 y:25.0];
290 NSLog(
@"Created new point: (%f, %f)", [newPoint getX], [newPoint getY]);
297- (void)demonstrateRouteOptions {
298 NSLog(
@"=== Route Options ===");
302 NCRouteOptions *routeOptions = [[NCRouteOptions alloc] initWithSmoothRadius:3.0 maxProjectionDistance:7.0 maxAdvance:2.5];
303 NSLog(
@"Created route options with smoothRadius: %f, maxProjectionDistance: %f, maxAdvance: %f",
304 [routeOptions getSmoothRadius], [routeOptions getMaxProjectionDistance], [routeOptions getMaxAdvance]);
308 NSArray<NCRouteOptions *> *optionsList = @[
309 [[NCRouteOptions alloc] initWithSmoothRadius:0.0 maxProjectionDistance:5.0 maxAdvance:2.0],
310 [[NCRouteOptions alloc] initWithSmoothRadius:2.0 maxProjectionDistance:10.0 maxAdvance:1.0],
311 [[NCRouteOptions alloc] initWithSmoothRadius:1.0 maxProjectionDistance:3.0 maxAdvance:3.0],
314 for (
int i = 0; i < optionsList.count; i++) {
315 NCRouteOptions *options = optionsList[i];
316 NSLog(
@"Options %d: smoothRadius=%f, maxProjectionDistance=%f, maxAdvance=%f",
317 i + 1, [options getSmoothRadius], [options getMaxProjectionDistance], [options getMaxAdvance]);
324- (void)demonstrateAdvancedAsyncRoutingFeatures {
325 NSLog(
@"=== Advanced Async Routing Features ===");
332 NSArray<NCLocationPoint *> *destinations = @[
333 [[NCLocationPoint alloc] initWithPoint:[[NCPoint alloc] initWithX:50.0 y:50.0] locationId:12345 sublocationId:1],
334 [[NCLocationPoint alloc] initWithPoint:[[NCPoint alloc] initWithX:100.0 y:100.0] locationId:12345 sublocationId:1],
335 [[NCLocationPoint alloc] initWithPoint:[[NCPoint alloc] initWithX:150.0 y:150.0] locationId:12345 sublocationId:1]
339 NSArray<NCRouteOptions *> *optionsList = @[
340 [[NCRouteOptions alloc] initWithSmoothRadius:2.0 maxProjectionDistance:5.0 maxAdvance:2.0],
341 [[NCRouteOptions alloc] initWithSmoothRadius:3.0 maxProjectionDistance:7.0 maxAdvance:1.5],
342 [[NCRouteOptions alloc] initWithSmoothRadius:1.0 maxProjectionDistance:3.0 maxAdvance:2.5],
346 NSMutableArray<NCRouteSession *> *sessions = [NSMutableArray array];
347 for (
int i = 0; i < destinations.count; i++) {
348 NCRouteSession *session = [
self.asyncRouteManager createRouteSession:destinations[i] routeOptions:optionsList[i]];
349 [sessions addObject:session];
350 NSLog(
@"Created session %d for destination: %f, %f",
351 i + 1, [destinations[i].getPoint getX], [destinations[i].getPoint getY]);
353 [session addRouteListener:
self];
355 [NSThread sleepForTimeInterval:1.0];
359 [NSThread sleepForTimeInterval:3.0];
362 for (
int i = 0; i < sessions.count; i++) {
365 [
self.asyncRouteManager cancelRouteSession:sessions[i]];
366 NSLog(
@"Cancelled session %d", i + 1);
369 [NSThread sleepForTimeInterval:1.0];
376- (void)demonstrateRouteStatusUsage {
377 NSLog(
@"=== RouteStatus Enum Usage ===");
381 NSLog(
@"Available RouteStatus values:");
382 NSArray *allStatuses = @[@(NCRouteStatusMissingGraph), @(NCRouteStatusMissingPosition), @(NCRouteStatusMissingRoute), @(NCRouteStatusMissingProjection), @(NCRouteStatusNewRoute)];
383 for (NSNumber *statusNumber in allStatuses) {
384 NCRouteStatus status = [statusNumber integerValue];
385 NSLog(
@" - %@: %@", @(status), @(status));
389 NCRouteStatus testStatus = NCRouteStatusNewRoute;
390 switch (testStatus) {
391 case NCRouteStatusNewRoute:
392 NSLog(
@"Router is ready for navigation");
394 case NCRouteStatusMissingGraph:
395 NSLog(
@"Router is missing the route graph");
397 case NCRouteStatusMissingPosition:
398 NSLog(
@"Router is missing the current position");
400 case NCRouteStatusMissingProjection:
401 NSLog(
@"Current position is off the route graph");
403 case NCRouteStatusMissingRoute:
404 NSLog(
@"Router unable to find the route to the destination point");
413- (void)demonstrateRouteSessionManagement {
414 NSLog(
@"=== Route Session Management ===");
421 NCPoint *destinationPoint = [[NCPoint alloc] initWithX:75.0 y:75.0];
422 NCLocationPoint *destinationLocationPoint = [[NCLocationPoint alloc] initWithPoint:destinationPoint locationId:12345 sublocationId:1];
423 NCRouteOptions *routeOptions = [[NCRouteOptions alloc] initWithSmoothRadius:2.0 maxProjectionDistance:5.0 maxAdvance:2.0];
426 NCRouteSession *defaultSession = [
self.asyncRouteManager createRouteSession:destinationLocationPoint routeOptions:routeOptions];
427 NSLog(
@"Created session with default tag");
430 NCRouteSession *taggedSession = [
self.asyncRouteManager createRouteSessionWithTag:destinationLocationPoint routeOptions:routeOptions tag:@"elevator"];
431 NSLog(
@"Created session with 'elevator' tag");
434 [defaultSession addRouteListener:
self];
435 [taggedSession addRouteListener:
self];
438 dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
442 [defaultSession removeRouteListener:
self];
443 [taggedSession removeRouteListener:
self];
444 NSLog(
@"Removed listeners from sessions");
448 [
self.asyncRouteManager cancelRouteSession:defaultSession];
449 [
self.asyncRouteManager cancelRouteSession:taggedSession];
450 NSLog(
@"Cancelled both sessions");
461 [
self.currentSession removeRouteListener:
self];
468 [
self.asyncRouteManager cancelRouteSession:
self.currentSession];
477 NSLog(
@"=== AsyncRouteManager Example ===");
479 [
self demonstrateAsyncRouteManagerMethods];
480 [
self demonstrateRouteEventTypes];
481 [
self demonstrateRouteOptions];
482 [
self demonstrateRouteStatusUsage];
483 [
self demonstrateRouteSessionManagement];
484 [
self demonstrateAdvancedAsyncRoutingFeatures];
487 [NSThread sleepForTimeInterval:3.0];
490 NSLog(
@"=== Example completed ===");
493#pragma mark - NCAsyncRouteListener
496- (void)onRouteChanged:(NCRouteStatus)status currentPath:(NCRoutePath *)currentPath {
497 NSLog(
@"Route changed with status: %@", @(status));
498 if (status == NCRouteStatusNewRoute && currentPath != nil) {
499 [
self demonstrateRoutePathUsage:currentPath];
501 NSLog(
@"Route not ready, status: %@", @(status));
507- (void)onRouteAdvanced:(
float)distance point:(NCLocationPoint *)point {
508 NSLog(
@"Route advanced: %f meters", distance);
509 [
self demonstrateLocationPointUsage:point];
518int main(
int argc,
const char * argv[]) {
521 [example runExample];