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"
8#import "NCGlobalPoint.h"
9#import "NCLocationPoint.h"
18@property (nonatomic, strong) NCNavigineSdk *
sdk;
24@implementation NavigationManagerExample
37- (void)initializeSdk {
41 self.sdk = [NCNavigineSdk getInstance];
46 [
self.sdk setUserHash:@"USER-HASH-HERE"];
51 [
self.sdk setServer:@"https://custom.navigine.com"];
56 self.locationManager = [
self.sdk getLocationManager];
61 self.navigationManager = [
self.sdk getNavigationManager:
self.locationManager];
65 NSLog(
@"LocationManager and NavigationManager successfully initialized");
67 }
@catch (NSException *exception) {
68 NSLog(
@"Error initializing SDK: %@", exception.reason);
75- (void)demonstrateNavigationManagerMethods {
77 NSLog(
@"NavigationManager not initialized");
83 [
self.navigationManager addPositionListener:
self];
88 [
self.navigationManager startLogRecording];
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];
100 NCGlobalPoint *globalPoint = [[NCGlobalPoint alloc] initWithLatitude:55.7558 longitude:37.6176];
101 [
self.navigationManager addLocationMeasurement:globalPoint accuracy:5.0f provider:@"gps"];
106 [
self.navigationManager stopLogRecording];
113- (void)demonstratePositionUsage:(NCPosition *)position {
114 if (position == nil) {
115 NSLog(
@"Position is null");
121 NCGlobalPoint *globalPoint = [position getPoint];
122 if (globalPoint != nil) {
123 [
self demonstrateGlobalPointUsage:globalPoint];
129 double accuracy = [position getAccuracy];
130 NSLog(
@"Position accuracy: %f meters", accuracy);
135 NSNumber *heading = [position getHeading];
136 if (heading != nil) {
137 NSLog(
@"Heading: %f radians", [heading doubleValue]);
143 NSNumber *headingAccuracy = [position getHeadingAccuracy];
144 if (headingAccuracy != nil) {
145 NSLog(
@"Heading accuracy: %f radians", [headingAccuracy doubleValue]);
151 NCLocationPoint *locationPoint = [position getLocationPoint];
152 if (locationPoint != nil) {
153 [
self demonstrateLocationPointUsage:locationPoint];
159 NSNumber *locationHeading = [position getLocationHeading];
160 if (locationHeading != nil) {
161 NSLog(
@"Location heading: %f radians", [locationHeading doubleValue]);
169- (void)demonstrateGlobalPointUsage:(NCGlobalPoint *)globalPoint {
170 if (globalPoint == nil) {
171 NSLog(
@"GlobalPoint is null");
177 double latitude = [globalPoint getLatitude];
178 NSLog(
@"Latitude: %f", latitude);
183 double longitude = [globalPoint getLongitude];
184 NSLog(
@"Longitude: %f", longitude);
189 NCGlobalPoint *newPoint = [[NCGlobalPoint alloc] initWithLatitude:latitude longitude:longitude];
190 NSLog(
@"Created new GlobalPoint: %@", newPoint);
197- (void)demonstrateLocationPointUsage:(NCLocationPoint *)locationPoint {
198 if (locationPoint == nil) {
199 NSLog(
@"LocationPoint is null");
205 NCPoint *point = [locationPoint getPoint];
207 [
self demonstratePointUsage:point];
213 int32_t locationId = [locationPoint getLocationId];
214 NSLog(
@"Location ID: %d", locationId);
219 int32_t sublocationId = [locationPoint getSublocationId];
220 NSLog(
@"Sublocation ID: %d", sublocationId);
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);
234- (void)demonstratePointUsage:(NCPoint *)point {
236 NSLog(
@"Point is null");
242 double x = [point getX];
243 NSLog(
@"Point X: %f", x);
248 double y = [point getY];
249 NSLog(
@"Point Y: %f", y);
254 NCPoint *newPoint = [[NCPoint alloc] initWithX:x y:y];
255 NSLog(
@"Created new Point: %@", newPoint);
262- (void)demonstrateLocationManagerIntegration {
264 NSLog(
@"LocationManager not initialized");
270 [
self.locationManager addLocationListener:
self];
275 [
self.locationManager setLocationId:12345];
280 int32_t currentLocationId = [
self.locationManager getLocationId];
281 NSLog(
@"Current location ID: %d", currentLocationId);
286 [
self.locationManager setLocationUpdateInterval:300];
291 [
self.locationManager commitChanges];
298- (void)demonstrateAdvancedNavigationFeatures {
299 NSLog(
@"=== Advanced Navigation Features ===");
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]
313 for (
int i = 0; i < checkPoints.count; i++) {
314 NCLocationPoint *locationPoint = [[NCLocationPoint alloc] initWithPoint:checkPoints[i] locationId:12345 sublocationId:1];
317 [
self.navigationManager addCheckPoint:locationPoint];
319 NSLog(
@"Added check point %d: %@", i + 1, locationPoint);
323 NSArray<NCGlobalPoint *> *measurements = @[
324 [[NCGlobalPoint alloc] initWithLatitude:55.7558 longitude:37.6176],
325 [[NCGlobalPoint alloc] initWithLatitude:40.7128 longitude:-74.0060],
326 [[NCGlobalPoint alloc] initWithLatitude:51.5074 longitude:-0.1278]
329 NSArray<NSString *> *providers = @[@"gps", @"network", @"fused"];
331 for (
int i = 0; i < measurements.count; i++) {
334 [
self.navigationManager addLocationMeasurement:measurements[i] accuracy:3.0f + i provider:providers[i % providers.count]];
336 NSLog(
@"Added measurement %d with provider: %@", i + 1, providers[i % providers.count]);
343- (void)demonstratePositionTrackingSimulation {
344 NSLog(
@"=== Position Tracking Simulation ===");
352 [
self.navigationManager startLogRecording];
356 for (
int i = 0; i < 5; i++) {
357 double lat = 55.7558 + (i * 0.001);
358 double lon = 37.6176 + (i * 0.001);
360 NCGlobalPoint *globalPoint = [[NCGlobalPoint alloc] initWithLatitude:lat longitude:lon];
363 [
self.navigationManager addLocationMeasurement:globalPoint accuracy:2.0f provider:@"simulated"];
366 NSLog(
@"Simulated position %d: %@", i + 1, globalPoint);
368 [NSThread sleepForTimeInterval:1.0];
373 [
self.navigationManager stopLogRecording];
384 [
self.navigationManager removePositionListener:
self];
393 NSLog(
@"=== NavigationManager Example ===");
395 [
self demonstrateNavigationManagerMethods];
396 [
self demonstrateLocationManagerIntegration];
397 [
self demonstrateAdvancedNavigationFeatures];
398 [
self demonstratePositionTrackingSimulation];
401 [NSThread sleepForTimeInterval:3.0];
404 NSLog(
@"=== Example completed ===");
407#pragma mark - NCPositionListener
410- (void)onPositionUpdated:(NCPosition *)position {
411 NSLog(
@"Position updated successfully");
412 [
self demonstratePositionUsage:position];
417- (void)onPositionError:(NSError *)error {
418 NSLog(
@"Position error: %@", error.localizedDescription);
422#pragma mark - NCLocationListener
425- (void)onLocationLoaded:(NCLocation *)location {
426 NSLog(
@"Location loaded for navigation");
427 if (location != nil) {
430 [
self.locationManager setLocationId:[location getId]];
437- (void)onLocationUploaded:(int32_t)locationId {
438 NSLog(
@"Location uploaded: %d", locationId);
443- (void)onLocationFailed:(int32_t)locationId error:(NSError *)error {
444 NSLog(
@"Failed to load location %d: %@", locationId, error.localizedDescription);
453int main(
int argc,
const char * argv[]) {
456 [example runExample];