Loading...
Searching...
No Matches
LocationManagerExample.swift
Go to the documentation of this file.
1import Foundation
2
3/**
4 * LocationManager usage example for Swift
5 * Demonstrates working with locations, sublocations, categories, and other location-related classes
6 */
7class LocationManagerExample: NSObject, NCLocationListener {
8 private var sdk: NCNavigineSdk?
9 private var locationManager: NCLocationManager?
10 private var currentLocation: NCLocation?
11
12 override init() {
13 super.init()
14 initializeSdk()
15 }
16
17 /**
18 * Initialize SDK and get LocationManager
19 */
20 private func initializeSdk() {
21 do {
22 // [swift_NavigineSdk_getInstance]
23 // Get SDK instance
24 sdk = NCNavigineSdk.getInstance()
25 // [swift_NavigineSdk_getInstance]
26
27 // [swift_NavigineSdk_setUserHash]
28 // Set user hash
29 sdk?.setUserHash("USER-HASH-HERE")
30 // [swift_NavigineSdk_setUserHash]
31
32 // [swift_NavigineSdk_setServer]
33 // Set server URL (optional)
34 sdk?.setServer("https://custom.navigine.com")
35 // [swift_NavigineSdk_setServer]
36
37 // [swift_NavigineSdk_getLocationManager]
38 // Get LocationManager for working with locations
39 locationManager = sdk?.getLocationManager()
40 // [swift_NavigineSdk_getLocationManager]
41
42 if locationManager != nil {
43 print("LocationManager successfully initialized")
44 }
45 } catch {
46 print("Error initializing SDK: \‍(error)")
47 }
48 }
49
50 /**
51 * Demonstrate LocationManager methods
52 */
53 func demonstrateLocationManagerMethods() {
54 guard let manager = locationManager else {
55 print("LocationManager not initialized")
56 return
57 }
58
59 // [swift_LocationManager_addLocationListener]
60 // Add location listener
61 manager.addLocationListener(self)
62 // [swift_LocationManager_addLocationListener]
63
64 // [swift_LocationManager_setLocationId]
65 // Set location ID to load
66 manager.setLocationId(12345)
67 // [swift_LocationManager_setLocationId]
68
69 // [swift_LocationManager_getLocationId]
70 // Get current location ID
71 let currentLocationId = manager.getLocationId()
72 print("Current location ID: \‍(currentLocationId)")
73 // [swift_LocationManager_getLocationId]
74
75 // [swift_LocationManager_setLocationUpdateInterval]
76 // Set location update interval (in seconds)
77 manager.setLocationUpdateInterval(600) // 10 minutes
78 // [swift_LocationManager_setLocationUpdateInterval]
79
80 // [swift_LocationManager_commitChanges]
81 // Commit changes
82 manager.commitChanges()
83 // [swift_LocationManager_commitChanges]
84
85 // [swift_LocationManager_revertChanges]
86 // Revert changes (if needed)
87 // manager.revertChanges()
88 // [swift_LocationManager_revertChanges]
89 }
90
91 /**
92 * Demonstrate Location class methods
93 */
94 func demonstrateLocationUsage(_ location: NCLocation) {
95 // [swift_Location_getId]
96 // Get location ID
97 let locationId = location.getId()
98 print("Location ID: \‍(locationId)")
99 // [swift_Location_getId]
100
101 // [swift_Location_getVersion]
102 // Get location version
103 let version = location.getVersion()
104 print("Location version: \‍(version)")
105 // [swift_Location_getVersion]
106
107 // [swift_Location_getName]
108 // Get location name
109 let name = location.getName()
110 print("Location name: \‍(name ?? "nil")")
111 // [swift_Location_getName]
112
113 // [swift_Location_getDescript]
114 // Get location description
115 let description = location.getDescript()
116 print("Location description: \‍(description ?? "nil")")
117 // [swift_Location_getDescript]
118
119 // [swift_Location_getModified]
120 // Check if location is modified
121 let isModified = location.getModified()
122 print("Location modified: \‍(isModified)")
123 // [swift_Location_getModified]
124
125 // [swift_Location_getGraphTags]
126 // Get available graph tags
127 let graphTags = location.getGraphTags()
128 print("Available graph tags: \‍(graphTags)")
129 // [swift_Location_getGraphTags]
130
131 // [swift_Location_getElevationGraph]
132 // Get elevation graph by tag
133 if let firstTag = graphTags.first {
134 let elevationGraph = location.getElevationGraph(firstTag)
135 if let elevationGraph = elevationGraph {
136 demonstrateElevationGraphUsage(elevationGraph)
137 }
138 }
139 // [swift_Location_getElevationGraph]
140
141 // [swift_Location_getCategories]
142 // Get all categories
143 let categories = location.getCategories()
144 print("Number of categories: \‍(categories.count)")
145 // [swift_Location_getCategories]
146
147 // [swift_Location_getCategoryById]
148 // Get category by ID
149 if let firstCategory = categories.first {
150 let category = location.getCategoryById(firstCategory.getId())
151 if let category = category {
152 demonstrateCategoryUsage(category)
153 }
154 }
155 // [swift_Location_getCategoryById]
156
157 // [swift_Location_getSublocations]
158 // Get all sublocations
159 let sublocations = location.getSublocations()
160 print("Number of sublocations: \‍(sublocations.count)")
161 // [swift_Location_getSublocations]
162
163 // [swift_Location_getSublocationById]
164 // Get sublocation by ID
165 if let firstSublocation = sublocations.first {
166 let sublocation = location.getSublocationById(firstSublocation.getId())
167 if let sublocation = sublocation {
168 demonstrateSublocationUsage(sublocation)
169 }
170 }
171 // [swift_Location_getSublocationById]
172 }
173
174 /**
175 * Demonstrate Category class methods
176 */
177 func demonstrateCategoryUsage(_ category: NCCategory) {
178 // [swift_Category_getId]
179 // Get category ID
180 let categoryId = category.getId()
181 print("Category ID: \‍(categoryId)")
182 // [swift_Category_getId]
183
184 // [swift_Category_getName]
185 // Get category name
186 let categoryName = category.getName()
187 print("Category name: \‍(categoryName ?? "nil")")
188 // [swift_Category_getName]
189
190 // [swift_Category_getImageUrl]
191 // Get category image URL
192 if let imageUrl = category.getImageUrl() {
193 print("Category image URL: \‍(imageUrl)")
194 }
195 // [swift_Category_getImageUrl]
196 }
197
198 /**
199 * Demonstrate Sublocation class methods
200 */
201 func demonstrateSublocationUsage(_ sublocation: NCSublocation) {
202 // [swift_Sublocation_getId]
203 // Get sublocation ID
204 let sublocationId = sublocation.getId()
205 print("Sublocation ID: \‍(sublocationId)")
206 // [swift_Sublocation_getId]
207
208 // [swift_Sublocation_getName]
209 // Get sublocation name
210 let sublocationName = sublocation.getName()
211 print("Sublocation name: \‍(sublocationName ?? "nil")")
212 // [swift_Sublocation_getName]
213
214 // [swift_Sublocation_getDescript]
215 // Get sublocation description
216 let sublocationDescription = sublocation.getDescript()
217 print("Sublocation description: \‍(sublocationDescription ?? "nil")")
218 // [swift_Sublocation_getDescript]
219
220 // [swift_Sublocation_getCategoryId]
221 // Get category ID
222 let categoryId = sublocation.getCategoryId()
223 print("Sublocation category ID: \‍(categoryId)")
224 // [swift_Sublocation_getCategoryId]
225
226 // [swift_Sublocation_getLocation]
227 // Get location ID
228 let locationId = sublocation.getLocation()
229 print("Sublocation location ID: \‍(locationId)")
230 // [swift_Sublocation_getLocation]
231
232 // [swift_Sublocation_getWidth]
233 // Get sublocation width in meters
234 let width = sublocation.getWidth()
235 print("Sublocation width: \‍(width) meters")
236 // [swift_Sublocation_getWidth]
237
238 // [swift_Sublocation_getHeight]
239 // Get sublocation height in meters
240 let height = sublocation.getHeight()
241 print("Sublocation height: \‍(height) meters")
242 // [swift_Sublocation_getHeight]
243
244 // [swift_Sublocation_getAltitude]
245 // Get sublocation altitude in meters
246 if let altitude = sublocation.getAltitude() {
247 print("Sublocation altitude: \‍(altitude) meters")
248 }
249 // [swift_Sublocation_getAltitude]
250
251 // [swift_Sublocation_getAzimuth]
252 // Get sublocation azimuth in degrees
253 let azimuth = sublocation.getAzimuth()
254 print("Sublocation azimuth: \‍(azimuth) degrees")
255 // [swift_Sublocation_getAzimuth]
256
257 // [swift_Sublocation_getOriginPoint]
258 // Get sublocation origin point in WGS84 coordinates
259 let originPoint = sublocation.getOriginPoint()
260 print("Sublocation origin point: \‍(originPoint.getLat()), \‍(originPoint.getLon())")
261 // [swift_Sublocation_getOriginPoint]
262
263 // [swift_Sublocation_getLevelId]
264 // Get sublocation level ID
265 let levelId = sublocation.getLevelId()
266 print("Sublocation level ID: \‍(levelId)")
267 // [swift_Sublocation_getLevelId]
268
269 // [swift_Sublocation_getExternalId]
270 // Get sublocation external ID
271 let externalId = sublocation.getExternalId()
272 print("Sublocation external ID: \‍(externalId)")
273 // [swift_Sublocation_getExternalId]
274
275 // [swift_Sublocation_getBuildingName]
276 // Get sublocation building name
277 let buildingName = sublocation.getBuildingName()
278 print("Sublocation building name: \‍(buildingName)")
279 // [swift_Sublocation_getBuildingName]
280
281 // [swift_Sublocation_getReferencePoints]
282 // Get reference points
283 let referencePoints = sublocation.getReferencePoints()
284 print("Number of reference points: \‍(referencePoints.count)")
285 // [swift_Sublocation_getReferencePoints]
286
287 // [swift_Sublocation_getVenues]
288 // Get venues
289 let venues = sublocation.getVenues()
290 print("Number of venues: \‍(venues.count)")
291 // [swift_Sublocation_getVenues]
292
293 // [swift_Sublocation_getZones]
294 // Get zones
295 let zones = sublocation.getZones()
296 print("Number of zones: \‍(zones.count)")
297 // [swift_Sublocation_getZones]
298
299 // [swift_Sublocation_getBeacons]
300 // Get beacons
301 let beacons = sublocation.getBeacons()
302 print("Number of beacons: \‍(beacons.count)")
303 // [swift_Sublocation_getBeacons]
304
305 // [swift_Sublocation_getWifis]
306 // Get WiFi access points
307 let wifis = sublocation.getWifis()
308 print("Number of WiFi access points: \‍(wifis.count)")
309 // [swift_Sublocation_getWifis]
310
311 // [swift_Sublocation_getEddystones]
312 // Get Eddystone beacons
313 let eddystones = sublocation.getEddystones()
314 print("Number of Eddystone beacons: \‍(eddystones.count)")
315 // [swift_Sublocation_getEddystones]
316
317 // [swift_Sublocation_getGraph]
318 // Get graph
319 let graph = sublocation.getGraph()
320 if let graph = graph {
321 demonstrateGraphUsage(graph)
322 }
323 // [swift_Sublocation_getGraph]
324
325 // [swift_Sublocation_getGraph_withTag]
326 // Get graph by tag
327 if let graphByTag = sublocation.getGraph("main") {
328 print("Found graph with tag \"main\"")
329 demonstrateGraphUsage(graphByTag)
330 }
331 // [swift_Sublocation_getGraph_withTag]
332
333 // [swift_Sublocation_getVenueById]
334 // Get venue by ID
335 if !venues.isEmpty {
336 if let venueById = sublocation.getVenueById(venues.first!.getId()) {
337 print("Found venue by ID: \‍(venueById.getId())")
338 demonstrateVenueUsage(venueById)
339 }
340 }
341 // [swift_Sublocation_getVenueById]
342
343 // [swift_Sublocation_getZoneById]
344 // Get zone by ID
345 if !zones.isEmpty {
346 if let zoneById = sublocation.getZoneById(zones.first!.getId()) {
347 print("Found zone by ID: \‍(zoneById.getId())")
348 demonstrateZoneUsage(zoneById)
349 }
350 }
351 // [swift_Sublocation_getZoneById]
352
353 // [swift_Sublocation_globalToLocal]
354 // Convert global coordinates to local coordinates
355 let globalPoint = NCGlobalPoint(lat: 55.7558, lon: 37.6176) // Moscow coordinates
356 let localPoint = sublocation.globalToLocal(globalPoint)
357 print("Global point \‍(globalPoint.getLat()), \‍(globalPoint.getLon()) converted to local: \‍(localPoint.getX()), \‍(localPoint.getY())")
358 // [swift_Sublocation_globalToLocal]
359
360 // [swift_Sublocation_localToGlobal]
361 // Convert local coordinates to global coordinates
362 let localPoint2 = NCLocationPoint(x: 100.0, y: 200.0)
363 let globalPoint2 = sublocation.localToGlobal(localPoint2)
364 print("Local point \‍(localPoint2.getX()), \‍(localPoint2.getY()) converted to global: \‍(globalPoint2.getLat()), \‍(globalPoint2.getLon())")
365 // [swift_Sublocation_localToGlobal]
366
367 // [swift_Sublocation_getImage]
368 // Get sublocation image
369 if let image = sublocation.getImage(1024) { // max texture size 1024
370 print("Sublocation image obtained with max texture size 1024")
371 }
372 // [swift_Sublocation_getImage]
373 }
374
375 /**
376 * Demonstrate Venue class methods
377 */
378 func demonstrateVenueUsage(_ venue: NCVenue) {
379 // [swift_Venue_getId]
380 // Get venue ID
381 let venueId = venue.getId()
382 print("Venue ID: \‍(venueId)")
383 // [swift_Venue_getId]
384
385 // [swift_Venue_getLocationId]
386 // Get venue location ID
387 let locationId = venue.getLocationId()
388 print("Venue location ID: \‍(locationId)")
389 // [swift_Venue_getLocationId]
390
391 // [swift_Venue_getSublocationId]
392 // Get venue sublocation ID
393 let sublocationId = venue.getSublocationId()
394 print("Venue sublocation ID: \‍(sublocationId)")
395 // [swift_Venue_getSublocationId]
396
397 // [swift_Venue_getName]
398 // Get venue name
399 let venueName = venue.getName()
400 print("Venue name: \‍(venueName ?? "nil")")
401 // [swift_Venue_getName]
402
403 // [swift_Venue_getPhone]
404 // Get venue phone
405 let phone = venue.getPhone()
406 print("Venue phone: \‍(phone ?? "nil")")
407 // [swift_Venue_getPhone]
408
409 // [swift_Venue_getDescript]
410 // Get venue description
411 let venueDescription = venue.getDescript()
412 print("Venue description: \‍(venueDescription ?? "nil")")
413 // [swift_Venue_getDescript]
414
415 // [swift_Venue_getAlias]
416 // Get venue alias
417 let alias = venue.getAlias()
418 print("Venue alias: \‍(alias ?? "nil")")
419 // [swift_Venue_getAlias]
420
421 // [swift_Venue_getCategoryId]
422 // Get category ID
423 let categoryId = venue.getCategoryId()
424 print("Venue category ID: \‍(categoryId)")
425 // [swift_Venue_getCategoryId]
426
427 // [swift_Venue_getImageUrl]
428 // Get venue image URL
429 if let imageUrl = venue.getImageUrl() {
430 print("Venue image URL: \‍(imageUrl)")
431 }
432 // [swift_Venue_getImageUrl]
433
434 // [swift_Venue_getPoint]
435 // Get venue point
436 let point = venue.getPoint()
437 if let point = point {
438 demonstratePointUsage(point)
439 }
440 // [swift_Venue_getPoint]
441 }
442
443 /**
444 * Demonstrate Zone class methods
445 */
446 func demonstrateZoneUsage(_ zone: NCZone) {
447 // [swift_Zone_getGuid]
448 if let guid = zone.getGuid() {
449 print("Zone GUID: \‍(guid)")
450 }
451 // [swift_Zone_getGuid]
452
453 // [swift_Zone_getId]
454 // Get zone ID
455 let zoneId = zone.getId()
456 print("Zone ID: \‍(zoneId)")
457 // [swift_Zone_getId]
458
459 // [swift_Zone_getLocationId]
460 // Get zone location ID
461 let locationId = zone.getLocationId()
462 print("Zone location ID: \‍(locationId)")
463 // [swift_Zone_getLocationId]
464
465 // [swift_Zone_getSublocationId]
466 // Get zone sublocation ID
467 let sublocationId = zone.getSublocationId()
468 print("Zone sublocation ID: \‍(sublocationId)")
469 // [swift_Zone_getSublocationId]
470
471 // [swift_Zone_getName]
472 // Get zone name
473 let zoneName = zone.getName()
474 print("Zone name: \‍(zoneName ?? "nil")")
475 // [swift_Zone_getName]
476
477 // [swift_Zone_getDescript]
478 // Get zone description
479 let zoneDescription = zone.getDescript()
480 print("Zone description: \‍(zoneDescription ?? "nil")")
481 // [swift_Zone_getDescript]
482
483 // [swift_Zone_getCategoryId]
484 // Get category ID
485 let categoryId = zone.getCategoryId()
486 print("Zone category ID: \‍(categoryId)")
487 // [swift_Zone_getCategoryId]
488
489 // [swift_Zone_getAlias]
490 // Get zone alias
491 let alias = zone.getAlias()
492 print("Zone alias: \‍(alias ?? "nil")")
493 // [swift_Zone_getAlias]
494
495 // [swift_Zone_getColor]
496 // Get zone color
497 let color = zone.getColor()
498 print("Zone color: \‍(color)")
499 // [swift_Zone_getColor]
500
501 // [swift_Zone_getPolygon]
502 // Get zone polygon
503 let polygon = zone.getPolygon()
504 print("Zone polygon points: \‍(polygon.count)")
505 // [swift_Zone_getPolygon]
506 }
507
508 /**
509 * Demonstrate Beacon class methods
510 */
511 func demonstrateBeaconUsage(_ beacon: NCBeacon) {
512 // [swift_Beacon_getPoint]
513 // Get beacon point
514 let point = beacon.getPoint()
515 if let point = point {
516 demonstratePointUsage(point)
517 }
518 // [swift_Beacon_getPoint]
519
520 // [swift_Beacon_getLocationId]
521 // Get beacon location ID
522 let locationId = beacon.getLocationId()
523 print("Beacon location ID: \‍(locationId)")
524 // [swift_Beacon_getLocationId]
525
526 // [swift_Beacon_getSublocationId]
527 // Get beacon sublocation ID
528 let sublocationId = beacon.getSublocationId()
529 print("Beacon sublocation ID: \‍(sublocationId)")
530 // [swift_Beacon_getSublocationId]
531
532 // [swift_Beacon_getName]
533 // Get beacon name
534 let beaconName = beacon.getName()
535 print("Beacon name: \‍(beaconName ?? "nil")")
536 // [swift_Beacon_getName]
537
538 // [swift_Beacon_getMajor]
539 // Get beacon major
540 let major = beacon.getMajor()
541 print("Beacon major: \‍(major)")
542 // [swift_Beacon_getMajor]
543
544 // [swift_Beacon_getMinor]
545 // Get beacon minor
546 let minor = beacon.getMinor()
547 print("Beacon minor: \‍(minor)")
548 // [swift_Beacon_getMinor]
549
550 // [swift_Beacon_getUuid]
551 // Get beacon UUID
552 let uuid = beacon.getUuid()
553 print("Beacon UUID: \‍(uuid ?? "nil")")
554 // [swift_Beacon_getUuid]
555
556 // [swift_Beacon_getPower]
557 // Get beacon power
558 let power = beacon.getPower()
559 if let power = power {
560 print("Beacon power: \‍(power)")
561 }
562 // [swift_Beacon_getPower]
563
564 // [swift_Beacon_getStatus]
565 // Get beacon status
566 let status = beacon.getStatus()
567 print("Beacon status: \‍(status)")
568 // [swift_Beacon_getStatus]
569 }
570
571 /**
572 * Demonstrate Wifi class methods
573 */
574 func demonstrateWifiUsage(_ wifi: NCWifi) {
575 // [swift_Wifi_getPoint]
576 // Get WiFi point
577 let point = wifi.getPoint()
578 if let point = point {
579 demonstratePointUsage(point)
580 }
581 // [swift_Wifi_getPoint]
582
583 // [swift_Wifi_getLocationId]
584 // Get WiFi location ID
585 let locationId = wifi.getLocationId()
586 print("WiFi location ID: \‍(locationId)")
587 // [swift_Wifi_getLocationId]
588
589 // [swift_Wifi_getSublocationId]
590 // Get WiFi sublocation ID
591 let sublocationId = wifi.getSublocationId()
592 print("WiFi sublocation ID: \‍(sublocationId)")
593 // [swift_Wifi_getSublocationId]
594
595 // [swift_Wifi_getName]
596 // Get WiFi name
597 let wifiName = wifi.getName()
598 print("WiFi name: \‍(wifiName ?? "nil")")
599 // [swift_Wifi_getName]
600
601 // [swift_Wifi_getMac]
602 // Get WiFi MAC address
603 let mac = wifi.getMac()
604 print("WiFi MAC: \‍(mac ?? "nil")")
605 // [swift_Wifi_getMac]
606
607 // [swift_Wifi_getStatus]
608 // Get WiFi status
609 let status = wifi.getStatus()
610 print("WiFi status: \‍(status)")
611 // [swift_Wifi_getStatus]
612 }
613
614 /**
615 * Demonstrate Eddystone class methods
616 */
617 func demonstrateEddystoneUsage(_ eddystone: NCEddystone) {
618 // [swift_Eddystone_getPoint]
619 // Get Eddystone point
620 let point = eddystone.getPoint()
621 if let point = point {
622 demonstratePointUsage(point)
623 }
624 // [swift_Eddystone_getPoint]
625
626 // [swift_Eddystone_getLocationId]
627 // Get Eddystone location ID
628 let locationId = eddystone.getLocationId()
629 print("Eddystone location ID: \‍(locationId)")
630 // [swift_Eddystone_getLocationId]
631
632 // [swift_Eddystone_getSublocationId]
633 // Get Eddystone sublocation ID
634 let sublocationId = eddystone.getSublocationId()
635 print("Eddystone sublocation ID: \‍(sublocationId)")
636 // [swift_Eddystone_getSublocationId]
637
638 // [swift_Eddystone_getName]
639 // Get Eddystone name
640 let eddystoneName = eddystone.getName()
641 print("Eddystone name: \‍(eddystoneName ?? "nil")")
642 // [swift_Eddystone_getName]
643
644 // [swift_Eddystone_getNamespaceId]
645 // Get Eddystone namespace ID
646 let namespaceId = eddystone.getNamespaceId()
647 print("Eddystone namespace ID: \‍(namespaceId ?? "nil")")
648 // [swift_Eddystone_getNamespaceId]
649
650 // [swift_Eddystone_getInstanceId]
651 // Get Eddystone instance ID
652 let instanceId = eddystone.getInstanceId()
653 print("Eddystone instance ID: \‍(instanceId ?? "nil")")
654 // [swift_Eddystone_getInstanceId]
655
656 // [swift_Eddystone_getPower]
657 // Get Eddystone power
658 let power = eddystone.getPower()
659 if let power = power {
660 print("Eddystone power: \‍(power)")
661 }
662 // [swift_Eddystone_getPower]
663
664 // [swift_Eddystone_getStatus]
665 // Get Eddystone status
666 let status = eddystone.getStatus()
667 print("Eddystone status: \‍(status)")
668 // [swift_Eddystone_getStatus]
669 }
670
671 /**
672 * Demonstrate Point class methods
673 */
674 func demonstratePointUsage(_ point: NCPoint) {
675 // [swift_Point_getX]
676 // Get X coordinate
677 let x = point.getX()
678 print("Point X: \‍(x)")
679 // [swift_Point_getX]
680
681 // [swift_Point_getY]
682 // Get Y coordinate
683 let y = point.getY()
684 print("Point Y: \‍(y)")
685 // [swift_Point_getY]
686 }
687
688 /**
689 * Demonstrate Graph class methods
690 */
691 func demonstrateGraphUsage(_ graph: NCGraph) {
692 // [swift_Graph_getVertices]
693 // Get graph vertices
694 let vertices = graph.getVertices()
695 print("Number of graph vertices: \‍(vertices.count)")
696 // [swift_Graph_getVertices]
697
698 // [swift_Graph_getEdges]
699 // Get graph edges
700 let edges = graph.getEdges()
701 print("Number of graph edges: \‍(edges.count)")
702 // [swift_Graph_getEdges]
703 }
704
705 /**
706 * Demonstrate GraphVertex class methods
707 */
708 func demonstrateGraphVertexUsage(_ vertex: NCGraphVertex) {
709 // [swift_GraphVertex_getId]
710 // Get vertex ID
711 let vertexId = vertex.getId()
712 print("Vertex ID: \‍(vertexId)")
713 // [swift_GraphVertex_getId]
714
715 // [swift_GraphVertex_getPoint]
716 // Get vertex point
717 let point = vertex.getPoint()
718 if let point = point {
719 demonstratePointUsage(point)
720 }
721 // [swift_GraphVertex_getPoint]
722
723 // [swift_GraphVertex_getName]
724 // Get vertex name
725 let name = vertex.getName()
726 print("Vertex name: \‍(name ?? "nil")")
727 // [swift_GraphVertex_getName]
728
729 // [swift_GraphVertex_getIsExternal]
730 // Get vertex external flag
731 let isExternal = vertex.getIsExternal()
732 print("Vertex is external: \‍(isExternal)")
733 // [swift_GraphVertex_getIsExternal]
734
735 // [swift_GraphVertex_getIsElevation]
736 // Get vertex elevation flag
737 let isElevation = vertex.getIsElevation()
738 print("Vertex is elevation: \‍(isElevation)")
739 // [swift_GraphVertex_getIsElevation]
740 }
741
742 /**
743 * Demonstrate GraphEdge class methods
744 */
745 func demonstrateGraphEdgeUsage(_ edge: NCGraphEdge) {
746 // [swift_GraphEdge_getWeight]
747 // Get edge weight
748 let weight = edge.getWeight()
749 print("Edge weight: \‍(weight)")
750 // [swift_GraphEdge_getWeight]
751
752 // [swift_GraphEdge_getDst]
753 // Get destination vertex ID
754 let dst = edge.getDst()
755 print("Edge destination ID: \‍(dst)")
756 // [swift_GraphEdge_getDst]
757
758 // [swift_GraphEdge_getSrc]
759 // Get source vertex ID
760 let src = edge.getSrc()
761 print("Edge source ID: \‍(src)")
762 // [swift_GraphEdge_getSrc]
763
764 // [swift_GraphEdge_getWeightCoef]
765 // Get edge weight coefficient
766 let weightCoef = edge.getWeightCoef()
767 print("Edge weight coefficient: \‍(weightCoef)")
768 // [swift_GraphEdge_getWeightCoef]
769 }
770
771 /**
772 * Demonstrate ElevationGraph class methods
773 */
774 func demonstrateElevationGraphUsage(_ elevationGraph: NCElevationGraph) {
775 // [swift_ElevationGraph_getEdges]
776 // Get elevation graph edges
777 let edges = elevationGraph.getEdges()
778 print("Number of elevation graph edges: \‍(edges.count)")
779
780 // Demonstrate each edge
781 for (index, edge) in edges.enumerated() {
782 print("Elevation graph edge \‍(index + 1):")
783 demonstrateGraphEdgeUsage(edge)
784 }
785 // [swift_ElevationGraph_getEdges]
786 }
787
788 /**
789 * Demonstrate TransmitterStatus enum
790 */
791 func demonstrateTransmitterStatus() {
792 // [swift_TransmitterStatus_values]
793 // Get all transmitter status values
794 print("Available transmitter statuses:")
795 print(" - NCTransmitterStatusActive: \‍(NCTransmitterStatusActive)")
796 print(" - NCTransmitterStatusInactive: \‍(NCTransmitterStatusInactive)")
797 // [swift_TransmitterStatus_values]
798 }
799
800 /**
801 * Clean up resources
802 */
803 func cleanup() {
804 if let manager = locationManager {
805 // [swift_LocationManager_removeLocationListener]
806 // Remove location listener
807 manager.removeLocationListener(self)
808 // [swift_LocationManager_removeLocationListener]
809 }
810 }
811
812 /**
813 * Main demonstration method
814 */
815 func runExample() {
816 print("=== LocationManager Example ===")
817
818 demonstrateLocationManagerMethods()
819 demonstrateTransmitterStatus()
820
821 // Wait a bit for location to load
822 Thread.sleep(forTimeInterval: 2.0)
823
824 cleanup()
825 print("=== Example completed ===")
826 }
827}
828
829// MARK: - NCLocationListener
830
831extension LocationManagerExample {
832 // [swift_LocationListener_onLocationLoaded]
833 func onLocationLoaded(_ location: NCLocation?) {
834 print("Location loaded successfully")
835 currentLocation = location
836 if let location = location {
837 demonstrateLocationUsage(location)
838 }
839 }
840 // [swift_LocationListener_onLocationLoaded]
841
842 // [swift_LocationListener_onLocationUploaded]
843 func onLocationUploaded(_ locationId: Int32) {
844 print("Location uploaded: \‍(locationId)")
845 }
846 // [swift_LocationListener_onLocationUploaded]
847
848 // [swift_LocationListener_onLocationFailed]
849 func onLocationFailed(_ locationId: Int32, error: Error?) {
850 print("Failed to load location \‍(locationId): \‍(error?.localizedDescription ?? "Unknown error")")
851 }
852 // [swift_LocationListener_onLocationFailed]
853}
854
855/**
856 * Function to run the example
857 */
858func main() {
859 let example = LocationManagerExample()
860 example.runExample()
861}
862
863// Run the example
864main()