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");
508 int32_t zoneId = [zone getId];
509 NSLog(
@"Zone ID: %d", zoneId);
514 int32_t locationId = [zone getLocationId];
515 NSLog(
@"Zone location ID: %d", locationId);
520 int32_t sublocationId = [zone getSublocationId];
521 NSLog(
@"Zone sublocation ID: %d", sublocationId);
526 NSString *zoneName = [zone getName];
527 NSLog(
@"Zone name: %@", zoneName);
532 NSString *zoneDescription = [zone getDescript];
533 NSLog(
@"Zone description: %@", zoneDescription);
538 int32_t categoryId = [zone getCategoryId];
539 NSLog(
@"Zone category ID: %d", categoryId);
544 NSString *alias = [zone getAlias];
545 NSLog(
@"Zone alias: %@", alias);
550 NSString *color = [zone getColor];
551 NSLog(
@"Zone color: %@", color);
556 NSArray<NCPoint *> *polygon = [zone getPolygon];
557 NSLog(
@"Zone polygon points: %lu", (
unsigned long)polygon.count);
564- (void)demonstrateBeaconUsage:(NCBeacon *)beacon {
566 NSLog(
@"Beacon is null");
572 NCPoint *point = [beacon getPoint];
574 [
self demonstratePointUsage:point];
580 int32_t locationId = [beacon getLocationId];
581 NSLog(
@"Beacon location ID: %d", locationId);
586 int32_t sublocationId = [beacon getSublocationId];
587 NSLog(
@"Beacon sublocation ID: %d", sublocationId);
592 NSString *beaconName = [beacon getName];
593 NSLog(
@"Beacon name: %@", beaconName);
598 int32_t major = [beacon getMajor];
599 NSLog(
@"Beacon major: %d", major);
604 int32_t minor = [beacon getMinor];
605 NSLog(
@"Beacon minor: %d", minor);
610 NSString *uuid = [beacon getUuid];
611 NSLog(
@"Beacon UUID: %@", uuid);
616 NSNumber *power = [beacon getPower];
618 NSLog(
@"Beacon power: %d", [power intValue]);
625 NSLog(
@"Beacon status: %ld", (
long)status);
632- (void)demonstrateWifiUsage:(NCWifi *)wifi {
634 NSLog(
@"WiFi is null");
640 NCPoint *point = [wifi getPoint];
642 [
self demonstratePointUsage:point];
648 int32_t locationId = [wifi getLocationId];
649 NSLog(
@"WiFi location ID: %d", locationId);
654 int32_t sublocationId = [wifi getSublocationId];
655 NSLog(
@"WiFi sublocation ID: %d", sublocationId);
660 NSString *wifiName = [wifi getName];
661 NSLog(
@"WiFi name: %@", wifiName);
666 NSString *mac = [wifi getMac];
667 NSLog(
@"WiFi MAC: %@", mac);
673 NSLog(
@"WiFi status: %ld", (
long)status);
680- (void)demonstrateEddystoneUsage:(NCEddystone *)eddystone {
681 if (eddystone == nil) {
682 NSLog(
@"Eddystone is null");
688 NCPoint *point = [eddystone getPoint];
690 [
self demonstratePointUsage:point];
696 int32_t locationId = [eddystone getLocationId];
697 NSLog(
@"Eddystone location ID: %d", locationId);
702 int32_t sublocationId = [eddystone getSublocationId];
703 NSLog(
@"Eddystone sublocation ID: %d", sublocationId);
708 NSString *eddystoneName = [eddystone getName];
709 NSLog(
@"Eddystone name: %@", eddystoneName);
714 NSString *namespaceId = [eddystone getNamespaceId];
715 NSLog(
@"Eddystone namespace ID: %@", namespaceId);
720 NSString *instanceId = [eddystone getInstanceId];
721 NSLog(
@"Eddystone instance ID: %@", instanceId);
726 NSNumber *power = [eddystone getPower];
728 NSLog(
@"Eddystone power: %d", [power intValue]);
735 NSLog(
@"Eddystone status: %ld", (
long)status);
742- (void)demonstratePointUsage:(NCPoint *)point {
744 NSLog(
@"Point is null");
750 double x = [point getX];
751 NSLog(
@"Point X: %f", x);
756 double y = [point getY];
757 NSLog(
@"Point Y: %f", y);
764- (void)demonstrateGraphUsage:(NCGraph *)graph {
766 NSLog(
@"Graph is null");
772 NSArray<NCGraphVertex *> *vertices = [graph getVertices];
773 NSLog(
@"Number of graph vertices: %lu", (
unsigned long)vertices.count);
778 NSArray<NCGraphEdge *> *edges = [graph getEdges];
779 NSLog(
@"Number of graph edges: %lu", (
unsigned long)edges.count);
786- (void)demonstrateGraphVertexUsage:(NCGraphVertex *)vertex {
788 NSLog(
@"GraphVertex is null");
794 int32_t vertexId = [vertex getId];
795 NSLog(
@"Vertex ID: %d", vertexId);
800 NCPoint *point = [vertex getPoint];
802 [
self demonstratePointUsage:point];
808 NSString *name = [vertex getName];
809 NSLog(
@"Vertex name: %@", name);
814 BOOL isExternal = [vertex getIsExternal];
815 NSLog(
@"Vertex is external: %@", isExternal ?
@"YES" :
@"NO");
820 BOOL isElevation = [vertex getIsElevation];
821 NSLog(
@"Vertex is elevation: %@", isElevation ?
@"YES" :
@"NO");
828- (void)demonstrateGraphEdgeUsage:(NCGraphEdge *)edge {
830 NSLog(
@"GraphEdge is null");
836 float weight = [edge getWeight];
837 NSLog(
@"Edge weight: %f", weight);
842 int32_t dst = [edge getDst];
843 NSLog(
@"Edge destination ID: %d", dst);
848 int32_t src = [edge getSrc];
849 NSLog(
@"Edge source ID: %d", src);
854 int32_t weightCoef = [edge getWeightCoef];
855 NSLog(
@"Edge weight coefficient: %d", weightCoef);
862- (void)demonstrateElevationGraphUsage:(NCElevationGraph *)elevationGraph {
863 if (elevationGraph == nil) {
864 NSLog(
@"ElevationGraph is null");
870 NSArray<NCGraphEdge *> *edges = [elevationGraph getEdges];
871 NSLog(
@"Number of elevation graph edges: %lu", (
unsigned long)edges.count);
874 for (
int i = 0; i < edges.count; i++) {
875 NCGraphEdge *edge = edges[i];
876 NSLog(
@"Elevation graph edge %d:", i + 1);
877 [
self demonstrateGraphEdgeUsage:edge];
885- (void)demonstrateTransmitterStatus {
888 NSLog(
@"Available transmitter statuses:");
889 NSLog(
@" - NCTransmitterStatusActive: %ld", (
long)NCTransmitterStatusActive);
890 NSLog(
@" - NCTransmitterStatusInactive: %ld", (
long)NCTransmitterStatusInactive);
898 if (
self.locationManager != nil) {
901 [
self.locationManager removeLocationListener:
self];
910 NSLog(
@"=== LocationManager Example ===");
912 [
self demonstrateLocationManagerMethods];
913 [
self demonstrateTransmitterStatus];
916 [NSThread sleepForTimeInterval:2.0];
919 NSLog(
@"=== Example completed ===");
922#pragma mark - NCLocationListener
925- (void)onLocationLoaded:(NCLocation *)location {
926 NSLog(
@"Location loaded successfully");
927 self.currentLocation = location;
928 if (location != nil) {
929 [
self demonstrateLocationUsage:location];
935- (void)onLocationUploaded:(int32_t)locationId {
936 NSLog(
@"Location uploaded: %d", locationId);
941- (void)onLocationFailed:(int32_t)locationId error:(NSError *)error {
942 NSLog(
@"Failed to load location %d: %@", locationId, error.localizedDescription);
951int main(
int argc,
const char * argv[]) {
954 [example runExample];