1#import <Foundation/Foundation.h>
26@property (nonatomic, strong) NCNavigineSdk *sdk;
27@property (nonatomic, strong) NCLocationManager *locationManager;
28@property (nonatomic, strong) NCLocation *currentLocation;
32@implementation LocationManagerExample
45- (void)initializeSdk {
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) {
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) {
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 NSString *buildingName = [sublocation getBuildingName];
320 NSLog(
@"Sublocation building name: %@", buildingName);
325 NSArray<NCReferencePoint *> *referencePoints = [sublocation getReferencePoints];
326 NSLog(
@"Number of reference points: %lu", (
unsigned long)referencePoints.count);
331 NSArray<NCVenue *> *venues = [sublocation getVenues];
332 NSLog(
@"Number of venues: %lu", (
unsigned long)venues.count);
337 NSArray<NCZone *> *zones = [sublocation getZones];
338 NSLog(
@"Number of zones: %lu", (
unsigned long)zones.count);
343 NSArray<NCBeacon *> *beacons = [sublocation getBeacons];
344 NSLog(
@"Number of beacons: %lu", (
unsigned long)beacons.count);
349 NSArray<NCWifi *> *wifis = [sublocation getWifis];
350 NSLog(
@"Number of WiFi access points: %lu", (
unsigned long)wifis.count);
355 NSArray<NCEddystone *> *eddystones = [sublocation getEddystones];
356 NSLog(
@"Number of Eddystone beacons: %lu", (
unsigned long)eddystones.count);
361 NCGraph *graph = [sublocation getGraph];
363 [
self demonstrateGraphUsage:graph];
369 NCGraph *graphByTag = [sublocation
getGraph:@"main"];
370 if (graphByTag != nil) {
371 NSLog(
@"Found graph with tag \"main\
"");
372 [
self demonstrateGraphUsage:graphByTag];
378 if (venues.count > 0) {
379 NCVenue *venueById = [sublocation
getVenueById:[venues.firstObject getId]];
380 if (venueById != nil) {
381 NSLog(
@"Found venue by ID: %d", [venueById getId]);
382 [
self demonstrateVenueUsage:venueById];
389 if (zones.count > 0) {
390 NCZone *zoneById = [sublocation
getZoneById:[zones.firstObject getId]];
391 if (zoneById != nil) {
392 NSLog(
@"Found zone by ID: %d", [zoneById getId]);
393 [
self demonstrateZoneUsage:zoneById];
400 NCGlobalPoint *globalPoint = [[
NCGlobalPoint alloc] initWithLat:55.7558 lon:37.6176];
401 NCLocationPoint *localPoint = [sublocation
globalToLocal:globalPoint];
402 NSLog(
@"Global point %.6f, %.6f converted to local: %.2f, %.2f",
403 [globalPoint getLat], [globalPoint getLon], [localPoint getX], [localPoint getY]);
408 NCLocationPoint *localPoint2 = [[
NCLocationPoint alloc] initWithX:100.0 y:200.0];
409 NCGlobalPoint *globalPoint2 = [sublocation
localToGlobal:localPoint2];
410 NSLog(
@"Local point %.2f, %.2f converted to global: %.6f, %.6f",
411 [localPoint2 getX], [localPoint2 getY], [globalPoint2 getLat], [globalPoint2 getLon]);
416 NCImageWrapper *image = [sublocation
getImage:@1024];
418 NSLog(
@"Sublocation image obtained with max texture size 1024");
426- (void)demonstrateVenueUsage:(NCVenue *)venue {
428 NSLog(
@"Venue is null");
434 int32_t venueId = [venue getId];
435 NSLog(
@"Venue ID: %d", venueId);
440 int32_t locationId = [venue getLocationId];
441 NSLog(
@"Venue location ID: %d", locationId);
446 int32_t sublocationId = [venue getSublocationId];
447 NSLog(
@"Venue sublocation ID: %d", sublocationId);
452 NSString *venueName = [venue getName];
453 NSLog(
@"Venue name: %@", venueName);
458 NSString *phone = [venue getPhone];
459 NSLog(
@"Venue phone: %@", phone);
464 NSString *venueDescription = [venue getDescript];
465 NSLog(
@"Venue description: %@", venueDescription);
470 NSString *alias = [venue getAlias];
471 NSLog(
@"Venue alias: %@", alias);
476 int32_t categoryId = [venue getCategoryId];
477 NSLog(
@"Venue category ID: %d", categoryId);
482 NSString *imageUrl = [venue getImageUrl];
483 if (imageUrl != nil) {
484 NSLog(
@"Venue image URL: %@", imageUrl);
490 NCPoint *point = [venue getPoint];
492 [
self demonstratePointUsage:point];
500- (void)demonstrateZoneUsage:(NCZone *)zone {
502 NSLog(
@"Zone is null");
507 NSNumber *zoneGuid = [zone getGuid];
508 if (zoneGuid != nil) {
509 NSLog(
@"Zone GUID: %@", zoneGuid);
515 int32_t zoneId = [zone getId];
516 NSLog(
@"Zone ID: %d", zoneId);
521 int32_t locationId = [zone getLocationId];
522 NSLog(
@"Zone location ID: %d", locationId);
527 int32_t sublocationId = [zone getSublocationId];
528 NSLog(
@"Zone sublocation ID: %d", sublocationId);
533 NSString *zoneName = [zone getName];
534 NSLog(
@"Zone name: %@", zoneName);
539 NSString *zoneDescription = [zone getDescript];
540 NSLog(
@"Zone description: %@", zoneDescription);
545 int32_t categoryId = [zone getCategoryId];
546 NSLog(
@"Zone category ID: %d", categoryId);
551 NSString *alias = [zone getAlias];
552 NSLog(
@"Zone alias: %@", alias);
557 UIColor *color = [zone getColor];
558 NSLog(
@"Zone color: %@", color);
563 NSArray<NCPoint *> *polygon = [zone getPolygon];
564 NSLog(
@"Zone polygon points: %lu", (
unsigned long)polygon.count);
571- (void)demonstrateBeaconUsage:(NCBeacon *)beacon {
573 NSLog(
@"Beacon is null");
579 NCPoint *point = [beacon getPoint];
581 [
self demonstratePointUsage:point];
587 int32_t locationId = [beacon getLocationId];
588 NSLog(
@"Beacon location ID: %d", locationId);
593 int32_t sublocationId = [beacon getSublocationId];
594 NSLog(
@"Beacon sublocation ID: %d", sublocationId);
599 NSString *beaconName = [beacon getName];
600 NSLog(
@"Beacon name: %@", beaconName);
605 int32_t major = [beacon getMajor];
606 NSLog(
@"Beacon major: %d", major);
611 int32_t minor = [beacon getMinor];
612 NSLog(
@"Beacon minor: %d", minor);
617 NSString *uuid = [beacon getUuid];
618 NSLog(
@"Beacon UUID: %@", uuid);
623 NSNumber *power = [beacon getPower];
625 NSLog(
@"Beacon power: %d", [power intValue]);
632 NSLog(
@"Beacon status: %ld", (
long)status);
639- (void)demonstrateWifiUsage:(NCWifi *)wifi {
641 NSLog(
@"WiFi is null");
647 NCPoint *point = [wifi getPoint];
649 [
self demonstratePointUsage:point];
655 int32_t locationId = [wifi getLocationId];
656 NSLog(
@"WiFi location ID: %d", locationId);
661 int32_t sublocationId = [wifi getSublocationId];
662 NSLog(
@"WiFi sublocation ID: %d", sublocationId);
667 NSString *wifiName = [wifi getName];
668 NSLog(
@"WiFi name: %@", wifiName);
673 NSString *mac = [wifi getMac];
674 NSLog(
@"WiFi MAC: %@", mac);
680 NSLog(
@"WiFi status: %ld", (
long)status);
687- (void)demonstrateEddystoneUsage:(NCEddystone *)eddystone {
688 if (eddystone == nil) {
689 NSLog(
@"Eddystone is null");
695 NCPoint *point = [eddystone getPoint];
697 [
self demonstratePointUsage:point];
703 int32_t locationId = [eddystone getLocationId];
704 NSLog(
@"Eddystone location ID: %d", locationId);
709 int32_t sublocationId = [eddystone getSublocationId];
710 NSLog(
@"Eddystone sublocation ID: %d", sublocationId);
715 NSString *eddystoneName = [eddystone getName];
716 NSLog(
@"Eddystone name: %@", eddystoneName);
721 NSString *namespaceId = [eddystone getNamespaceId];
722 NSLog(
@"Eddystone namespace ID: %@", namespaceId);
727 NSString *instanceId = [eddystone getInstanceId];
728 NSLog(
@"Eddystone instance ID: %@", instanceId);
733 NSNumber *power = [eddystone getPower];
735 NSLog(
@"Eddystone power: %d", [power intValue]);
742 NSLog(
@"Eddystone status: %ld", (
long)status);
749- (void)demonstratePointUsage:(NCPoint *)point {
751 NSLog(
@"Point is null");
757 double x = [point getX];
758 NSLog(
@"Point X: %f", x);
763 double y = [point getY];
764 NSLog(
@"Point Y: %f", y);
771- (void)demonstrateGraphUsage:(NCGraph *)graph {
773 NSLog(
@"Graph is null");
779 NSArray<NCGraphVertex *> *vertices = [graph getVertices];
780 NSLog(
@"Number of graph vertices: %lu", (
unsigned long)vertices.count);
785 NSArray<NCGraphEdge *> *edges = [graph getEdges];
786 NSLog(
@"Number of graph edges: %lu", (
unsigned long)edges.count);
793- (void)demonstrateGraphVertexUsage:(NCGraphVertex *)vertex {
795 NSLog(
@"GraphVertex is null");
801 int32_t vertexId = [vertex getId];
802 NSLog(
@"Vertex ID: %d", vertexId);
807 NCPoint *point = [vertex getPoint];
809 [
self demonstratePointUsage:point];
815 NSString *name = [vertex getName];
816 NSLog(
@"Vertex name: %@", name);
821 BOOL isExternal = [vertex getIsExternal];
822 NSLog(
@"Vertex is external: %@", isExternal ?
@"YES" :
@"NO");
827 BOOL isElevation = [vertex getIsElevation];
828 NSLog(
@"Vertex is elevation: %@", isElevation ?
@"YES" :
@"NO");
835- (void)demonstrateGraphEdgeUsage:(NCGraphEdge *)edge {
837 NSLog(
@"GraphEdge is null");
843 float weight = [edge getWeight];
844 NSLog(
@"Edge weight: %f", weight);
849 int32_t dst = [edge getDst];
850 NSLog(
@"Edge destination ID: %d", dst);
855 int32_t src = [edge getSrc];
856 NSLog(
@"Edge source ID: %d", src);
861 int32_t weightCoef = [edge getWeightCoef];
862 NSLog(
@"Edge weight coefficient: %d", weightCoef);
869- (void)demonstrateElevationGraphUsage:(NCElevationGraph *)elevationGraph {
870 if (elevationGraph == nil) {
871 NSLog(
@"ElevationGraph is null");
877 NSArray<NCGraphEdge *> *edges = [elevationGraph getEdges];
878 NSLog(
@"Number of elevation graph edges: %lu", (
unsigned long)edges.count);
881 for (
int i = 0; i < edges.count; i++) {
882 NCGraphEdge *edge = edges[i];
883 NSLog(
@"Elevation graph edge %d:", i + 1);
884 [
self demonstrateGraphEdgeUsage:edge];
892- (void)demonstrateTransmitterStatus {
895 NSLog(
@"Available transmitter statuses:");
896 NSLog(
@" - NCTransmitterStatusActive: %ld", (
long)NCTransmitterStatusActive);
897 NSLog(
@" - NCTransmitterStatusInactive: %ld", (
long)NCTransmitterStatusInactive);
905 if (
self.locationManager != nil) {
908 [
self.locationManager removeLocationListener:
self];
917 NSLog(
@"=== LocationManager Example ===");
919 [
self demonstrateLocationManagerMethods];
920 [
self demonstrateTransmitterStatus];
923 [NSThread sleepForTimeInterval:2.0];
926 NSLog(
@"=== Example completed ===");
929#pragma mark - NCLocationListener
932- (void)onLocationLoaded:(NCLocation *)location {
933 NSLog(
@"Location loaded successfully");
934 self.currentLocation = location;
935 if (location != nil) {
936 [
self demonstrateLocationUsage:location];
942- (void)onLocationUploaded:(int32_t)locationId {
943 NSLog(
@"Location uploaded: %d", locationId);
948- (void)onLocationFailed:(int32_t)locationId error:(NSError *)error {
949 NSLog(
@"Failed to load location %d: %@", locationId, error.localizedDescription);
958int main(
int argc,
const char * argv[]) {
961 [example runExample];