Loading...
Searching...
No Matches
NavigationManagerExample.m
Go to the documentation of this file.
1#import <Foundation/Foundation.h>
2#import "NCNavigineSdk.h"
3#import "NCLocationManager.h"
4#import "NCLocationListener.h"
5#import "NCNavigationManager.h"
6#import "NCPositionListener.h"
7#import "NCPosition.h"
8#import "NCGlobalPoint.h"
9#import "NCLocationPoint.h"
10#import "NCPoint.h"
11
16@interface NavigationManagerExample : NSObject <NCPositionListener, NCLocationListener>
17
18@property (nonatomic, strong) NCNavigineSdk *sdk;
19@property (nonatomic, strong) NCLocationManager *locationManager;
20@property (nonatomic, strong) NCNavigationManager *navigationManager;
21
22@end
23
24@implementation NavigationManagerExample
25
26- (instancetype)init {
27 self = [super init];
28 if (self) {
29 [self initializeSdk];
30 }
31 return self;
32}
33
37- (void)initializeSdk {
38 @try {
39 // [objc_NavigineSdk_getInstance]
40 // Get SDK instance
41 self.sdk = [NCNavigineSdk getInstance];
42 // [objc_NavigineSdk_getInstance]
43
44 // [objc_NavigineSdk_setUserHash]
45 // Set user hash
46 [self.sdk setUserHash:@"USER-HASH-HERE"];
47 // [objc_NavigineSdk_setUserHash]
48
49 // [objc_NavigineSdk_setServer]
50 // Set server URL (optional)
51 [self.sdk setServer:@"https://custom.navigine.com"];
52 // [objc_NavigineSdk_setServer]
53
54 // [objc_NavigineSdk_getLocationManager]
55 // Get LocationManager for working with locations
56 self.locationManager = [self.sdk getLocationManager];
57 // [objc_NavigineSdk_getLocationManager]
58
59 // [objc_NavigineSdk_getNavigationManager]
60 // Get NavigationManager for working with navigation
61 self.navigationManager = [self.sdk getNavigationManager:self.locationManager];
62 // [objc_NavigineSdk_getNavigationManager]
63
64 if (self.locationManager != nil && self.navigationManager != nil) {
65 NSLog(@"LocationManager and NavigationManager successfully initialized");
66 }
67 } @catch (NSException *exception) {
68 NSLog(@"Error initializing SDK: %@", exception.reason);
69 }
70}
71
75- (void)demonstrateNavigationManagerMethods {
76 if (self.navigationManager == nil) {
77 NSLog(@"NavigationManager not initialized");
78 return;
79 }
80
81 // [objc_NavigationManager_addPositionListener]
82 // Add position listener
83 [self.navigationManager addPositionListener:self];
84 // [objc_NavigationManager_addPositionListener]
85
86 // [objc_NavigationManager_startLogRecording]
87 // Start log recording
88 [self.navigationManager startLogRecording];
89 // [objc_NavigationManager_startLogRecording]
90
91 // [objc_NavigationManager_addCheckPoint]
92 // Add check point
93 NCPoint *point = [[NCPoint alloc] initWithX:10.0 y:20.0];
94 NCLocationPoint *locationPoint = [[NCLocationPoint alloc] initWithPoint:point locationId:12345 sublocationId:1];
95 [self.navigationManager addCheckPoint:locationPoint];
96 // [objc_NavigationManager_addCheckPoint]
97
98 // [objc_NavigationManager_addLocationMeasurement]
99 // Add location measurement
100 NCGlobalPoint *globalPoint = [[NCGlobalPoint alloc] initWithLatitude:55.7558 longitude:37.6176]; // Moscow coordinates
101 [self.navigationManager addLocationMeasurement:globalPoint accuracy:5.0f provider:@"gps"];
102 // [objc_NavigationManager_addLocationMeasurement]
103
104 // [objc_NavigationManager_stopLogRecording]
105 // Stop log recording
106 [self.navigationManager stopLogRecording];
107 // [objc_NavigationManager_stopLogRecording]
108}
109
113- (void)demonstratePositionUsage:(NCPosition *)position {
114 if (position == nil) {
115 NSLog(@"Position is null");
116 return;
117 }
118
119 // [objc_Position_getPoint]
120 // Get global point (WGS84 coordinates)
121 NCGlobalPoint *globalPoint = [position getPoint];
122 if (globalPoint != nil) {
123 [self demonstrateGlobalPointUsage:globalPoint];
124 }
125 // [objc_Position_getPoint]
126
127 // [objc_Position_getAccuracy]
128 // Get position accuracy
129 double accuracy = [position getAccuracy];
130 NSLog(@"Position accuracy: %f meters", accuracy);
131 // [objc_Position_getAccuracy]
132
133 // [objc_Position_getHeading]
134 // Get heading (angle of rotation about the -Z axis in radians)
135 NSNumber *heading = [position getHeading];
136 if (heading != nil) {
137 NSLog(@"Heading: %f radians", [heading doubleValue]);
138 }
139 // [objc_Position_getHeading]
140
141 // [objc_Position_getHeadingAccuracy]
142 // Get heading accuracy
143 NSNumber *headingAccuracy = [position getHeadingAccuracy];
144 if (headingAccuracy != nil) {
145 NSLog(@"Heading accuracy: %f radians", [headingAccuracy doubleValue]);
146 }
147 // [objc_Position_getHeadingAccuracy]
148
149 // [objc_Position_getLocationPoint]
150 // Get location point (metrics coordinates)
151 NCLocationPoint *locationPoint = [position getLocationPoint];
152 if (locationPoint != nil) {
153 [self demonstrateLocationPointUsage:locationPoint];
154 }
155 // [objc_Position_getLocationPoint]
156
157 // [objc_Position_getLocationHeading]
158 // Get location heading (with respect to sublocation north)
159 NSNumber *locationHeading = [position getLocationHeading];
160 if (locationHeading != nil) {
161 NSLog(@"Location heading: %f radians", [locationHeading doubleValue]);
162 }
163 // [objc_Position_getLocationHeading]
164}
165
169- (void)demonstrateGlobalPointUsage:(NCGlobalPoint *)globalPoint {
170 if (globalPoint == nil) {
171 NSLog(@"GlobalPoint is null");
172 return;
173 }
174
175 // [objc_GlobalPoint_getLatitude]
176 // Get latitude
177 double latitude = [globalPoint getLatitude];
178 NSLog(@"Latitude: %f", latitude);
179 // [objc_GlobalPoint_getLatitude]
180
181 // [objc_GlobalPoint_getLongitude]
182 // Get longitude
183 double longitude = [globalPoint getLongitude];
184 NSLog(@"Longitude: %f", longitude);
185 // [objc_GlobalPoint_getLongitude]
186
187 // [objc_GlobalPoint_constructor]
188 // Create new GlobalPoint
189 NCGlobalPoint *newPoint = [[NCGlobalPoint alloc] initWithLatitude:latitude longitude:longitude];
190 NSLog(@"Created new GlobalPoint: %@", newPoint);
191 // [objc_GlobalPoint_constructor]
192}
193
197- (void)demonstrateLocationPointUsage:(NCLocationPoint *)locationPoint {
198 if (locationPoint == nil) {
199 NSLog(@"LocationPoint is null");
200 return;
201 }
202
203 // [objc_LocationPoint_getPoint]
204 // Get point coordinates
205 NCPoint *point = [locationPoint getPoint];
206 if (point != nil) {
207 [self demonstratePointUsage:point];
208 }
209 // [objc_LocationPoint_getPoint]
210
211 // [objc_LocationPoint_getLocationId]
212 // Get location ID
213 int32_t locationId = [locationPoint getLocationId];
214 NSLog(@"Location ID: %d", locationId);
215 // [objc_LocationPoint_getLocationId]
216
217 // [objc_LocationPoint_getSublocationId]
218 // Get sublocation ID
219 int32_t sublocationId = [locationPoint getSublocationId];
220 NSLog(@"Sublocation ID: %d", sublocationId);
221 // [objc_LocationPoint_getSublocationId]
222
223 // [objc_LocationPoint_constructor]
224 // Create new LocationPoint
225 NCPoint *newPoint = [[NCPoint alloc] initWithX:15.0 y:25.0];
226 NCLocationPoint *newLocationPoint = [[NCLocationPoint alloc] initWithPoint:newPoint locationId:locationId sublocationId:sublocationId];
227 NSLog(@"Created new LocationPoint: %@", newLocationPoint);
228 // [objc_LocationPoint_constructor]
229}
230
234- (void)demonstratePointUsage:(NCPoint *)point {
235 if (point == nil) {
236 NSLog(@"Point is null");
237 return;
238 }
239
240 // [objc_Point_getX]
241 // Get X coordinate
242 double x = [point getX];
243 NSLog(@"Point X: %f", x);
244 // [objc_Point_getX]
245
246 // [objc_Point_getY]
247 // Get Y coordinate
248 double y = [point getY];
249 NSLog(@"Point Y: %f", y);
250 // [objc_Point_getY]
251
252 // [objc_Point_constructor]
253 // Create new Point
254 NCPoint *newPoint = [[NCPoint alloc] initWithX:x y:y];
255 NSLog(@"Created new Point: %@", newPoint);
256 // [objc_Point_constructor]
257}
258
262- (void)demonstrateLocationManagerIntegration {
263 if (self.locationManager == nil) {
264 NSLog(@"LocationManager not initialized");
265 return;
266 }
267
268 // [objc_LocationManager_addLocationListener]
269 // Add location listener for navigation integration
270 [self.locationManager addLocationListener:self];
271 // [objc_LocationManager_addLocationListener]
272
273 // [objc_LocationManager_setLocationId]
274 // Set location ID to load
275 [self.locationManager setLocationId:12345];
276 // [objc_LocationManager_setLocationId]
277
278 // [objc_LocationManager_getLocationId]
279 // Get current location ID
280 int32_t currentLocationId = [self.locationManager getLocationId];
281 NSLog(@"Current location ID: %d", currentLocationId);
282 // [objc_LocationManager_getLocationId]
283
284 // [objc_LocationManager_setLocationUpdateInterval]
285 // Set location update interval
286 [self.locationManager setLocationUpdateInterval:300]; // 5 minutes
287 // [objc_LocationManager_setLocationUpdateInterval]
288
289 // [objc_LocationManager_commitChanges]
290 // Commit changes
291 [self.locationManager commitChanges];
292 // [objc_LocationManager_commitChanges]
293}
294
298- (void)demonstrateAdvancedNavigationFeatures {
299 NSLog(@"=== Advanced Navigation Features ===");
300
301 if (self.navigationManager == nil) {
302 return;
303 }
304
305 // Create multiple check points for path tracking
306 NSArray<NCPoint *> *checkPoints = @[
307 [[NCPoint alloc] initWithX:0.0 y:0.0],
308 [[NCPoint alloc] initWithX:10.0 y:10.0],
309 [[NCPoint alloc] initWithX:20.0 y:20.0],
310 [[NCPoint alloc] initWithX:30.0 y:30.0]
311 ];
312
313 for (int i = 0; i < checkPoints.count; i++) {
314 NCLocationPoint *locationPoint = [[NCLocationPoint alloc] initWithPoint:checkPoints[i] locationId:12345 sublocationId:1];
315 // [objc_NavigationManager_addCheckPoint]
316 // Add check point for path tracking
317 [self.navigationManager addCheckPoint:locationPoint];
318 // [objc_NavigationManager_addCheckPoint]
319 NSLog(@"Added check point %d: %@", i + 1, locationPoint);
320 }
321
322 // Add location measurements with different providers
323 NSArray<NCGlobalPoint *> *measurements = @[
324 [[NCGlobalPoint alloc] initWithLatitude:55.7558 longitude:37.6176], // Moscow
325 [[NCGlobalPoint alloc] initWithLatitude:40.7128 longitude:-74.0060], // New York
326 [[NCGlobalPoint alloc] initWithLatitude:51.5074 longitude:-0.1278] // London
327 ];
328
329 NSArray<NSString *> *providers = @[@"gps", @"network", @"fused"];
330
331 for (int i = 0; i < measurements.count; i++) {
332 // [objc_NavigationManager_addLocationMeasurement]
333 // Add location measurement with different providers
334 [self.navigationManager addLocationMeasurement:measurements[i] accuracy:3.0f + i provider:providers[i % providers.count]];
335 // [objc_NavigationManager_addLocationMeasurement]
336 NSLog(@"Added measurement %d with provider: %@", i + 1, providers[i % providers.count]);
337 }
338}
339
343- (void)demonstratePositionTrackingSimulation {
344 NSLog(@"=== Position Tracking Simulation ===");
345
346 if (self.navigationManager == nil) {
347 return;
348 }
349
350 // [objc_NavigationManager_startLogRecording]
351 // Start log recording for position tracking
352 [self.navigationManager startLogRecording];
353 // [objc_NavigationManager_startLogRecording]
354
355 // Simulate position updates
356 for (int i = 0; i < 5; i++) {
357 double lat = 55.7558 + (i * 0.001); // Move north
358 double lon = 37.6176 + (i * 0.001); // Move east
359
360 NCGlobalPoint *globalPoint = [[NCGlobalPoint alloc] initWithLatitude:lat longitude:lon];
361 // [objc_NavigationManager_addLocationMeasurement]
362 // Add simulated location measurement
363 [self.navigationManager addLocationMeasurement:globalPoint accuracy:2.0f provider:@"simulated"];
364 // [objc_NavigationManager_addLocationMeasurement]
365
366 NSLog(@"Simulated position %d: %@", i + 1, globalPoint);
367
368 [NSThread sleepForTimeInterval:1.0]; // Wait 1 second between updates
369 }
370
371 // [objc_NavigationManager_stopLogRecording]
372 // Stop log recording
373 [self.navigationManager stopLogRecording];
374 // [objc_NavigationManager_stopLogRecording]
375}
376
380- (void)cleanup {
381 if (self.navigationManager != nil) {
382 // [objc_NavigationManager_removePositionListener]
383 // Remove position listener
384 [self.navigationManager removePositionListener:self];
385 // [objc_NavigationManager_removePositionListener]
386 }
387}
388
392- (void)runExample {
393 NSLog(@"=== NavigationManager Example ===");
394
395 [self demonstrateNavigationManagerMethods];
396 [self demonstrateLocationManagerIntegration];
397 [self demonstrateAdvancedNavigationFeatures];
398 [self demonstratePositionTrackingSimulation];
399
400 // Wait a bit for position updates
401 [NSThread sleepForTimeInterval:3.0];
402
403 [self cleanup];
404 NSLog(@"=== Example completed ===");
405}
406
407#pragma mark - NCPositionListener
408
409// [objc_PositionListener_onPositionUpdated]
410- (void)onPositionUpdated:(NCPosition *)position {
411 NSLog(@"Position updated successfully");
412 [self demonstratePositionUsage:position];
413}
414// [objc_PositionListener_onPositionUpdated]
415
416// [objc_PositionListener_onPositionError]
417- (void)onPositionError:(NSError *)error {
418 NSLog(@"Position error: %@", error.localizedDescription);
419}
420// [objc_PositionListener_onPositionError]
421
422#pragma mark - NCLocationListener
423
424// [objc_LocationListener_onLocationLoaded]
425- (void)onLocationLoaded:(NCLocation *)location {
426 NSLog(@"Location loaded for navigation");
427 if (location != nil) {
428 // [objc_LocationManager_setLocationId]
429 // Set location ID for navigation
430 [self.locationManager setLocationId:[location getId]];
431 // [objc_LocationManager_setLocationId]
432 }
433}
434// [objc_LocationListener_onLocationLoaded]
435
436// [objc_LocationListener_onLocationUploaded]
437- (void)onLocationUploaded:(int32_t)locationId {
438 NSLog(@"Location uploaded: %d", locationId);
439}
440// [objc_LocationListener_onLocationUploaded]
441
442// [objc_LocationListener_onLocationFailed]
443- (void)onLocationFailed:(int32_t)locationId error:(NSError *)error {
444 NSLog(@"Failed to load location %d: %@", locationId, error.localizedDescription);
445}
446// [objc_LocationListener_onLocationFailed]
447
448@end
449
453int main(int argc, const char * argv[]) {
454 @autoreleasepool {
455 NavigationManagerExample *example = [[NavigationManagerExample alloc] init];
456 [example runExample];
457 }
458 return 0;
459}