1#import <Foundation/Foundation.h>
2#import <NavigineSDK/NavigineSDK.h>
10@property (nonatomic, strong) NCNavigineSdk *
sdk;
17- (void)demonstrateRouteManagerMethods;
18- (void)demonstrateRoutePathUsage:(NSArray<NCRoutePath *> *)paths;
19- (void)demonstrateRouteEventUsage:(NCRouteEvent *)event;
20- (void)demonstrateRouteEventTypes;
21- (void)demonstrateLocationPointUsage:(NCLocationPoint *)locationPoint;
22- (void)demonstratePointUsage:(NCPoint *)point;
23- (void)demonstrateAdvancedRoutingFeatures;
24- (void)demonstrateRoutePlanningSimulation;
30@implementation RouteManagerExample
50 [
self.sdk setUserHash:@"USER-HASH-HERE"];
55 [
self.sdk setServer:@"https://custom.navigine.com"];
60 self.locationManager = [
self.sdk getLocationManager];
65 self.navigationManager = [
self.sdk getNavigationManager:
self.locationManager];
70 self.routeManager = [
self.sdk getRouteManager:
self.locationManager navigationManager:
self.navigationManager];
74 NSLog(
@"LocationManager, NavigationManager and RouteManager successfully initialized");
76 }
@catch (NSException *exception) {
77 NSLog(
@"Error initializing SDK: %@", exception.reason);
92- (void)demonstrateRouteManagerMethods {
94 NSLog(
@"RouteManager not initialized");
100 [
self.routeManager addRouteListener:
self];
105 [
self.routeManager setGraphTag:@"main"];
110 NSString *currentGraphTag = [
self.routeManager getGraphTag];
111 NSLog(
@"Current graph tag: %@", currentGraphTag);
116 NSArray<NSString *> *graphTags = [
self.routeManager getGraphTags];
117 NSLog(
@"Available graph tags: %@", graphTags);
121 NCPoint *startPoint = [[NCPoint alloc] initWithX:10.0 y:20.0];
122 NCPoint *endPoint = [[NCPoint alloc] initWithX:50.0 y:60.0];
123 NCLocationPoint *startLocationPoint = [[NCLocationPoint alloc] initWithPoint:startPoint locationId:12345 sublocationId:1];
124 NCLocationPoint *endLocationPoint = [[NCLocationPoint alloc] initWithPoint:endPoint locationId:12345 sublocationId:1];
128 NCRoutePath *routePath = [
self.routeManager makeRoute:startLocationPoint to:endLocationPoint];
129 NSLog(
@"Route created with length: %f meters", [routePath getLength]);
134 NSArray<NCLocationPoint *> *destinations = @[
135 [[NCLocationPoint alloc] initWithPoint:[[NCPoint alloc] initWithX:30.0 y:40.0] locationId:12345 sublocationId:1],
136 [[NCLocationPoint alloc] initWithPoint:[[NCPoint alloc] initWithX:70.0 y:80.0] locationId:12345 sublocationId:1]
138 NSArray<NCRoutePath *> *routePaths = [
self.routeManager makeRoutes:startLocationPoint to:destinations];
139 NSLog(
@"Created %lu routes", (
unsigned long)routePaths.count);
144 [
self.routeManager setTarget:endLocationPoint];
149 NCLocationPoint *additionalTarget = [[NCLocationPoint alloc] initWithPoint:[[NCPoint alloc] initWithX:90.0 y:100.0] locationId:12345 sublocationId:1];
150 [
self.routeManager addTarget:additionalTarget];
155 [
self.routeManager cancelTarget];
160 [
self.routeManager clearTargets];
167- (void)demonstrateRoutePathUsage:(NSArray<NCRoutePath *> *)paths {
168 for (
int i = 0; i < paths.count; i++) {
169 NCRoutePath *path = paths[
i];
170 NSLog(
@"=== Route Path %d ===", i + 1);
174 double length = [
path getLength];
175 NSLog(
@"Route length: %f meters", length);
180 NSArray<NCLocationPoint *> *points = [
path getPoints];
181 NSLog(
@"Route has %lu points", (
unsigned long)points.count);
182 for (
int j = 0; j < points.count; j++) {
189 NSArray<NCRouteEvent *> *events = [
path getEvents];
190 NSLog(
@"Route has %lu events", (
unsigned long)events.count);
191 for (
int j = 0; j < events.count; j++) {
198 NCRoutePath *headPath = [
path head:10.0];
199 if (headPath != nil) {
200 NSLog(
@"Head path length: %f meters", [headPath getLength]);
206 NCRoutePath *tailPath = [
path tail:10.0];
207 if (tailPath != nil) {
208 NSLog(
@"Tail path length: %f meters", [tailPath getLength]);
217- (void)demonstrateRouteEventUsage:(NCRouteEvent *)event {
220 NCRouteEventType type = [
event getType];
221 NSLog(
@"Event type: %ld", (
long)type);
226 int32_t value = [
event getValue];
227 NSLog(
@"Event value: %d", value);
232 double distance = [
event getDistance];
233 NSLog(
@"Event distance: %f meters", distance);
238 NCRouteEvent *newEvent = [[
NCRouteEvent alloc] initWithType:type value:value distance:distance];
239 NSLog(
@"Created new RouteEvent: %@", newEvent);
246- (void)demonstrateRouteEventTypes {
249 NSArray<NSNumber *> *types = @[
250 @(NCRouteEventTypeTurnLeft),
251 @(NCRouteEventTypeTurnRight),
252 @(NCRouteEventTypeTransition)
254 NSLog(
@"Available route event types:");
255 for (NSNumber *type in types) {
256 NSLog(
@" - %ld", (
long)[type integerValue]);
264- (void)demonstrateLocationPointUsage:(NCLocationPoint *)locationPoint {
276 NSLog(
@"Location ID: %d", locationId);
282 NSLog(
@"Sublocation ID: %d", sublocationId);
287 NCPoint *newPoint = [[
NCPoint alloc] initWithX:15.0 y:25.0];
288 NCLocationPoint *newLocationPoint = [[
NCLocationPoint alloc] initWithPoint:newPoint locationId:locationId sublocationId:sublocationId];
289 NSLog(
@"Created new LocationPoint: %@", newLocationPoint);
296- (void)demonstratePointUsage:(NCPoint *)point {
299 double x = [
point getX];
300 NSLog(
@"Point X: %f", x);
305 double y = [
point getY];
306 NSLog(
@"Point Y: %f", y);
311 NCPoint *newPoint = [[
NCPoint alloc] initWithX:x y:y];
312 NSLog(
@"Created new Point: %@", newPoint);
319- (void)demonstrateAdvancedRoutingFeatures {
320 NSLog(
@"=== Advanced Routing Features ===");
327 NSArray<NSString *> *graphTags = @[@"main", @"elevator", @"stairs"];
329 for (NSString *tag in graphTags) {
332 [
self.routeManager setGraphTag:tag];
335 NSLog(
@"Routing with graph tag: %@", tag);
338 NCPoint *startPoint = [[NCPoint alloc] initWithX:0.0 y:0.0];
339 NCPoint *endPoint = [[NCPoint alloc] initWithX:100.0 y:100.0];
340 NCLocationPoint *startLocationPoint = [[NCLocationPoint alloc] initWithPoint:startPoint locationId:12345 sublocationId:1];
341 NCLocationPoint *endLocationPoint = [[NCLocationPoint alloc] initWithPoint:endPoint locationId:12345 sublocationId:1];
345 NCRoutePath *routePath = [
self.routeManager makeRoute:startLocationPoint to:endLocationPoint];
348 NSLog(
@"Route with tag '%@' has length: %f meters", tag, [routePath getLength]);
355- (void)demonstrateRoutePlanningSimulation {
356 NSLog(
@"=== Route Planning Simulation ===");
363 NSArray<NCLocationPoint *> *targets = @[
364 [[NCLocationPoint alloc] initWithPoint:[[NCPoint alloc] initWithX:50.0 y:50.0] locationId:12345 sublocationId:1],
365 [[NCLocationPoint alloc] initWithPoint:[[NCPoint alloc] initWithX:100.0 y:100.0] locationId:12345 sublocationId:1],
366 [[NCLocationPoint alloc] initWithPoint:[[NCPoint alloc] initWithX:150.0 y:150.0] locationId:12345 sublocationId:1]
371 [
self.routeManager setTarget:targets[0]];
374 NSLog(
@"Set target 1: %@", targets[0]);
375 [NSThread sleepForTimeInterval:1.0];
379 for (
int i = 1; i < targets.count; i++) {
380 [
self.routeManager addTarget:targets[i]];
381 NSLog(
@"Added target %d: %@", i + 1, targets[i]);
382 [NSThread sleepForTimeInterval:1.0];
388 [
self.routeManager cancelTarget];
389 NSLog(
@"Cancelled current target");
392 [NSThread sleepForTimeInterval:1.0];
396 [
self.routeManager clearTargets];
397 NSLog(
@"Cleared all targets");
408 [
self.routeManager removeRouteListener:
self];
417 NSLog(
@"=== RouteManager Example ===");
419 [
self demonstrateRouteManagerMethods];
420 [
self demonstrateRouteEventTypes];
421 [
self demonstrateAdvancedRoutingFeatures];
422 [
self demonstrateRoutePlanningSimulation];
425 [NSThread sleepForTimeInterval:3.0];
428 NSLog(
@"=== Example completed ===");
431#pragma mark - NCRouteListener
434- (void)onPathsUpdated:(NSArray<NCRoutePath *> *)paths {
435 NSLog(
@"Routes updated successfully");
436 [
self demonstrateRoutePathUsage:paths];
445int main(
int argc,
const char * argv[]) {
448 [example runExample];