1#import <Foundation/Foundation.h>
2#import "NCNavigineSdk.h"
3#import "NCLocationManager.h"
4#import "NCLocationListener.h"
7#import "NCSublocation.h"
12#import "NCEddystone.h"
15#import "NCGraphVertex.h"
16#import "NCGraphEdge.h"
17#import "NCElevationGraph.h"
18#import "NCTransmitterStatus.h"
24@interface LocationManagerExample : NSObject <NCLocationListener>
26@property (nonatomic, strong) NCNavigineSdk *sdk;
27@property (nonatomic, strong) NCLocationManager *locationManager;
28@property (nonatomic, strong) NCLocation *currentLocation;
32@implementation LocationManagerExample
45- (void)initializeSdk {
49 self.sdk = [NCNavigineSdk getInstance];
54 [
self.sdk setUserHash:@"USER-HASH-HERE"];
59 [
self.sdk setServer:@"https://custom.navigine.com"];
64 self.locationManager = [
self.sdk getLocationManager];
67 if (
self.locationManager != nil) {
68 NSLog(
@"LocationManager successfully initialized");
70 }
@catch (NSException *exception) {
71 NSLog(
@"Error initializing SDK: %@", exception.reason);
78- (void)demonstrateLocationManagerMethods {
79 if (
self.locationManager == nil) {
80 NSLog(
@"LocationManager not initialized");
86 [
self.locationManager addLocationListener:
self];
91 [
self.locationManager setLocationId:12345];
96 int32_t currentLocationId = [
self.locationManager getLocationId];
97 NSLog(
@"Current location ID: %d", currentLocationId);
102 [
self.locationManager setLocationUpdateInterval:600];
107 [
self.locationManager commitChanges];
119- (void)demonstrateLocationUsage:(NCLocation *)location {
120 if (location == nil) {
121 NSLog(
@"Location is null");
127 int32_t locationId = [location getId];
128 NSLog(
@"Location ID: %d", locationId);
133 int32_t version = [location getVersion];
134 NSLog(
@"Location version: %d", version);
139 NSString *name = [location getName];
140 NSLog(
@"Location name: %@", name);
145 NSString *description = [location getDescript];
146 NSLog(
@"Location description: %@", description);
151 BOOL isModified = [location getModified];
152 NSLog(
@"Location modified: %@", isModified ?
@"YES" :
@"NO");
157 NSArray<NSString *> *graphTags = [location getGraphTags];
158 NSLog(
@"Available graph tags: %@", graphTags);
163 if (graphTags.count > 0) {
164 NCElevationGraph *elevationGraph = [location getElevationGraph:graphTags[0]];
165 if (elevationGraph != nil) {
166 [
self demonstrateElevationGraphUsage:elevationGraph];
173 NSArray<NCCategory *> *categories = [location getCategories];
174 NSLog(
@"Number of categories: %lu", (
unsigned long)categories.count);
179 if (categories.count > 0) {
180 NCCategory *category = [location getCategoryById:[categories[0] getId]];
181 if (category != nil) {
182 [
self demonstrateCategoryUsage:category];
189 NSArray<NCSublocation *> *sublocations = [location getSublocations];
190 NSLog(
@"Number of sublocations: %lu", (
unsigned long)sublocations.count);
195 if (sublocations.count > 0) {
196 NCSublocation *sublocation = [location getSublocationById:[sublocations[0] getId]];
197 if (sublocation != nil) {
198 [
self demonstrateSublocationUsage:sublocation];
207- (void)demonstrateCategoryUsage:(NCCategory *)category {
208 if (category == nil) {
209 NSLog(
@"Category is null");
215 int32_t categoryId = [category getId];
216 NSLog(
@"Category ID: %d", categoryId);
221 NSString *categoryName = [category getName];
222 NSLog(
@"Category name: %@", categoryName);
227 NSString *imageUrl = [category getImageUrl];
228 if (imageUrl != nil) {
229 NSLog(
@"Category image URL: %@", imageUrl);
237- (void)demonstrateSublocationUsage:(NCSublocation *)sublocation {
238 if (sublocation == nil) {
239 NSLog(
@"Sublocation is null");
245 int32_t sublocationId = [sublocation getId];
246 NSLog(
@"Sublocation ID: %d", sublocationId);
251 NSString *sublocationName = [sublocation getName];
252 NSLog(
@"Sublocation name: %@", sublocationName);
257 NSString *sublocationDescription = [sublocation getDescript];
258 NSLog(
@"Sublocation description: %@", sublocationDescription);
263 int32_t categoryId = [sublocation getCategoryId];
264 NSLog(
@"Sublocation category ID: %d", categoryId);
269 int32_t locationId = [sublocation getLocation];
270 NSLog(
@"Sublocation location ID: %d", locationId);
275 double width = [sublocation getWidth];
276 NSLog(
@"Sublocation width: %.2f meters", width);
281 double height = [sublocation getHeight];
282 NSLog(
@"Sublocation height: %.2f meters", height);
287 NSNumber *altitude = [sublocation getAltitude];
288 if (altitude != nil) {
289 NSLog(
@"Sublocation altitude: %.2f meters", [altitude doubleValue]);
295 double azimuth = [sublocation getAzimuth];
296 NSLog(
@"Sublocation azimuth: %.2f degrees", azimuth);
301 NCGlobalPoint *originPoint = [sublocation getOriginPoint];
302 NSLog(
@"Sublocation origin point: %.6f, %.6f", [originPoint getLat], [originPoint getLon]);
307 NSString *levelId = [sublocation getLevelId];
308 NSLog(
@"Sublocation level ID: %@", levelId);
313 NSString *externalId = [sublocation getExternalId];
314 NSLog(
@"Sublocation external ID: %@", externalId);
319 NSArray<NCReferencePoint *> *referencePoints = [sublocation getReferencePoints];
320 NSLog(
@"Number of reference points: %lu", (
unsigned long)referencePoints.count);
325 NSArray<NCVenue *> *venues = [sublocation getVenues];
326 NSLog(
@"Number of venues: %lu", (
unsigned long)venues.count);
331 NSArray<NCZone *> *zones = [sublocation getZones];
332 NSLog(
@"Number of zones: %lu", (
unsigned long)zones.count);
337 NSArray<NCBeacon *> *beacons = [sublocation getBeacons];
338 NSLog(
@"Number of beacons: %lu", (
unsigned long)beacons.count);
343 NSArray<NCWifi *> *wifis = [sublocation getWifis];
344 NSLog(
@"Number of WiFi access points: %lu", (
unsigned long)wifis.count);
349 NSArray<NCEddystone *> *eddystones = [sublocation getEddystones];
350 NSLog(
@"Number of Eddystone beacons: %lu", (
unsigned long)eddystones.count);
355 NCGraph *graph = [sublocation getGraph];
357 [
self demonstrateGraphUsage:graph];
363 NCGraph *graphByTag = [sublocation getGraph:@"main"];
364 if (graphByTag != nil) {
365 NSLog(
@"Found graph with tag \"main\
"");
366 [
self demonstrateGraphUsage:graphByTag];
372 if (venues.count > 0) {
373 NCVenue *venueById = [sublocation getVenueById:[venues.firstObject getId]];
374 if (venueById != nil) {
375 NSLog(
@"Found venue by ID: %d", [venueById getId]);
376 [
self demonstrateVenueUsage:venueById];
383 if (zones.count > 0) {
384 NCZone *zoneById = [sublocation getZoneById:[zones.firstObject getId]];
385 if (zoneById != nil) {
386 NSLog(
@"Found zone by ID: %d", [zoneById getId]);
387 [
self demonstrateZoneUsage:zoneById];
394 NCGlobalPoint *globalPoint = [[NCGlobalPoint alloc] initWithLat:55.7558 lon:37.6176];
395 NCLocationPoint *localPoint = [sublocation globalToLocal:globalPoint];
396 NSLog(
@"Global point %.6f, %.6f converted to local: %.2f, %.2f",
397 [globalPoint getLat], [globalPoint getLon], [localPoint getX], [localPoint getY]);
402 NCLocationPoint *localPoint2 = [[NCLocationPoint alloc] initWithX:100.0 y:200.0];
403 NCGlobalPoint *globalPoint2 = [sublocation localToGlobal:localPoint2];
404 NSLog(
@"Local point %.2f, %.2f converted to global: %.6f, %.6f",
405 [localPoint2 getX], [localPoint2 getY], [globalPoint2 getLat], [globalPoint2 getLon]);
410 NCImageWrapper *image = [sublocation getImage:@1024];
412 NSLog(
@"Sublocation image obtained with max texture size 1024");
420- (void)demonstrateVenueUsage:(NCVenue *)venue {
422 NSLog(
@"Venue is null");
428 int32_t venueId = [venue getId];
429 NSLog(
@"Venue ID: %d", venueId);
434 int32_t locationId = [venue getLocationId];
435 NSLog(
@"Venue location ID: %d", locationId);
440 int32_t sublocationId = [venue getSublocationId];
441 NSLog(
@"Venue sublocation ID: %d", sublocationId);
446 NSString *venueName = [venue getName];
447 NSLog(
@"Venue name: %@", venueName);
452 NSString *phone = [venue getPhone];
453 NSLog(
@"Venue phone: %@", phone);
458 NSString *venueDescription = [venue getDescript];
459 NSLog(
@"Venue description: %@", venueDescription);
464 NSString *alias = [venue getAlias];
465 NSLog(
@"Venue alias: %@", alias);
470 int32_t categoryId = [venue getCategoryId];
471 NSLog(
@"Venue category ID: %d", categoryId);
476 NSString *imageUrl = [venue getImageUrl];
477 if (imageUrl != nil) {
478 NSLog(
@"Venue image URL: %@", imageUrl);
484 NCPoint *point = [venue getPoint];
486 [
self demonstratePointUsage:point];
494- (void)demonstrateZoneUsage:(NCZone *)zone {
496 NSLog(
@"Zone is null");
502 int32_t zoneId = [zone getId];
503 NSLog(
@"Zone ID: %d", zoneId);
508 int32_t locationId = [zone getLocationId];
509 NSLog(
@"Zone location ID: %d", locationId);
514 int32_t sublocationId = [zone getSublocationId];
515 NSLog(
@"Zone sublocation ID: %d", sublocationId);
520 NSString *zoneName = [zone getName];
521 NSLog(
@"Zone name: %@", zoneName);
526 NSString *zoneDescription = [zone getDescript];
527 NSLog(
@"Zone description: %@", zoneDescription);
532 int32_t categoryId = [zone getCategoryId];
533 NSLog(
@"Zone category ID: %d", categoryId);
538 NSString *alias = [zone getAlias];
539 NSLog(
@"Zone alias: %@", alias);
544 NSString *color = [zone getColor];
545 NSLog(
@"Zone color: %@", color);
550 NSArray<NCPoint *> *polygon = [zone getPolygon];
551 NSLog(
@"Zone polygon points: %lu", (
unsigned long)polygon.count);
558- (void)demonstrateBeaconUsage:(NCBeacon *)beacon {
560 NSLog(
@"Beacon is null");
566 NCPoint *point = [beacon getPoint];
568 [
self demonstratePointUsage:point];
574 int32_t locationId = [beacon getLocationId];
575 NSLog(
@"Beacon location ID: %d", locationId);
580 int32_t sublocationId = [beacon getSublocationId];
581 NSLog(
@"Beacon sublocation ID: %d", sublocationId);
586 NSString *beaconName = [beacon getName];
587 NSLog(
@"Beacon name: %@", beaconName);
592 int32_t major = [beacon getMajor];
593 NSLog(
@"Beacon major: %d", major);
598 int32_t minor = [beacon getMinor];
599 NSLog(
@"Beacon minor: %d", minor);
604 NSString *uuid = [beacon getUuid];
605 NSLog(
@"Beacon UUID: %@", uuid);
610 NSNumber *power = [beacon getPower];
612 NSLog(
@"Beacon power: %d", [power intValue]);
618 NCTransmitterStatus status = [beacon getStatus];
619 NSLog(
@"Beacon status: %ld", (
long)status);
626- (void)demonstrateWifiUsage:(NCWifi *)wifi {
628 NSLog(
@"WiFi is null");
634 NCPoint *point = [wifi getPoint];
636 [
self demonstratePointUsage:point];
642 int32_t locationId = [wifi getLocationId];
643 NSLog(
@"WiFi location ID: %d", locationId);
648 int32_t sublocationId = [wifi getSublocationId];
649 NSLog(
@"WiFi sublocation ID: %d", sublocationId);
654 NSString *wifiName = [wifi getName];
655 NSLog(
@"WiFi name: %@", wifiName);
660 NSString *mac = [wifi getMac];
661 NSLog(
@"WiFi MAC: %@", mac);
666 NCTransmitterStatus status = [wifi getStatus];
667 NSLog(
@"WiFi status: %ld", (
long)status);
674- (void)demonstrateEddystoneUsage:(NCEddystone *)eddystone {
675 if (eddystone == nil) {
676 NSLog(
@"Eddystone is null");
682 NCPoint *point = [eddystone getPoint];
684 [
self demonstratePointUsage:point];
690 int32_t locationId = [eddystone getLocationId];
691 NSLog(
@"Eddystone location ID: %d", locationId);
696 int32_t sublocationId = [eddystone getSublocationId];
697 NSLog(
@"Eddystone sublocation ID: %d", sublocationId);
702 NSString *eddystoneName = [eddystone getName];
703 NSLog(
@"Eddystone name: %@", eddystoneName);
708 NSString *namespaceId = [eddystone getNamespaceId];
709 NSLog(
@"Eddystone namespace ID: %@", namespaceId);
714 NSString *instanceId = [eddystone getInstanceId];
715 NSLog(
@"Eddystone instance ID: %@", instanceId);
720 NSNumber *power = [eddystone getPower];
722 NSLog(
@"Eddystone power: %d", [power intValue]);
728 NCTransmitterStatus status = [eddystone getStatus];
729 NSLog(
@"Eddystone status: %ld", (
long)status);
736- (void)demonstratePointUsage:(NCPoint *)point {
738 NSLog(
@"Point is null");
744 double x = [point getX];
745 NSLog(
@"Point X: %f", x);
750 double y = [point getY];
751 NSLog(
@"Point Y: %f", y);
758- (void)demonstrateGraphUsage:(NCGraph *)graph {
760 NSLog(
@"Graph is null");
766 NSArray<NCGraphVertex *> *vertices = [graph getVertices];
767 NSLog(
@"Number of graph vertices: %lu", (
unsigned long)vertices.count);
772 NSArray<NCGraphEdge *> *edges = [graph getEdges];
773 NSLog(
@"Number of graph edges: %lu", (
unsigned long)edges.count);
780- (void)demonstrateGraphVertexUsage:(NCGraphVertex *)vertex {
782 NSLog(
@"GraphVertex is null");
788 int32_t vertexId = [vertex getId];
789 NSLog(
@"Vertex ID: %d", vertexId);
794 NCPoint *point = [vertex getPoint];
796 [
self demonstratePointUsage:point];
802 NSString *name = [vertex getName];
803 NSLog(
@"Vertex name: %@", name);
808 BOOL isExternal = [vertex getIsExternal];
809 NSLog(
@"Vertex is external: %@", isExternal ?
@"YES" :
@"NO");
814 BOOL isElevation = [vertex getIsElevation];
815 NSLog(
@"Vertex is elevation: %@", isElevation ?
@"YES" :
@"NO");
822- (void)demonstrateGraphEdgeUsage:(NCGraphEdge *)edge {
824 NSLog(
@"GraphEdge is null");
830 float weight = [edge getWeight];
831 NSLog(
@"Edge weight: %f", weight);
836 int32_t dst = [edge getDst];
837 NSLog(
@"Edge destination ID: %d", dst);
842 int32_t src = [edge getSrc];
843 NSLog(
@"Edge source ID: %d", src);
848 int32_t weightCoef = [edge getWeightCoef];
849 NSLog(
@"Edge weight coefficient: %d", weightCoef);
856- (void)demonstrateElevationGraphUsage:(NCElevationGraph *)elevationGraph {
857 if (elevationGraph == nil) {
858 NSLog(
@"ElevationGraph is null");
864 NSArray<NCGraphEdge *> *edges = [elevationGraph getEdges];
865 NSLog(
@"Number of elevation graph edges: %lu", (
unsigned long)edges.count);
868 for (
int i = 0; i < edges.count; i++) {
869 NCGraphEdge *edge = edges[i];
870 NSLog(
@"Elevation graph edge %d:", i + 1);
871 [
self demonstrateGraphEdgeUsage:edge];
879- (void)demonstrateTransmitterStatus {
882 NSLog(
@"Available transmitter statuses:");
883 NSLog(
@" - NCTransmitterStatusActive: %ld", (
long)NCTransmitterStatusActive);
884 NSLog(
@" - NCTransmitterStatusInactive: %ld", (
long)NCTransmitterStatusInactive);
892 if (
self.locationManager != nil) {
895 [
self.locationManager removeLocationListener:
self];
904 NSLog(
@"=== LocationManager Example ===");
906 [
self demonstrateLocationManagerMethods];
907 [
self demonstrateTransmitterStatus];
910 [NSThread sleepForTimeInterval:2.0];
913 NSLog(
@"=== Example completed ===");
916#pragma mark - NCLocationListener
919- (void)onLocationLoaded:(NCLocation *)location {
920 NSLog(
@"Location loaded successfully");
921 self.currentLocation = location;
922 if (location != nil) {
923 [
self demonstrateLocationUsage:location];
929- (void)onLocationUploaded:(int32_t)locationId {
930 NSLog(
@"Location uploaded: %d", locationId);
935- (void)onLocationFailed:(int32_t)locationId error:(NSError *)error {
936 NSLog(
@"Failed to load location %d: %@", locationId, error.localizedDescription);
945int main(
int argc,
const char * argv[]) {
948 [example runExample];