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_getReferencePoints]
276 // Get reference points
277 let referencePoints = sublocation.getReferencePoints()
278 print("Number of reference points: \‍(referencePoints.count)")
279 // [swift_Sublocation_getReferencePoints]
280
281 // [swift_Sublocation_getVenues]
282 // Get venues
283 let venues = sublocation.getVenues()
284 print("Number of venues: \‍(venues.count)")
285 // [swift_Sublocation_getVenues]
286
287 // [swift_Sublocation_getZones]
288 // Get zones
289 let zones = sublocation.getZones()
290 print("Number of zones: \‍(zones.count)")
291 // [swift_Sublocation_getZones]
292
293 // [swift_Sublocation_getBeacons]
294 // Get beacons
295 let beacons = sublocation.getBeacons()
296 print("Number of beacons: \‍(beacons.count)")
297 // [swift_Sublocation_getBeacons]
298
299 // [swift_Sublocation_getWifis]
300 // Get WiFi access points
301 let wifis = sublocation.getWifis()
302 print("Number of WiFi access points: \‍(wifis.count)")
303 // [swift_Sublocation_getWifis]
304
305 // [swift_Sublocation_getEddystones]
306 // Get Eddystone beacons
307 let eddystones = sublocation.getEddystones()
308 print("Number of Eddystone beacons: \‍(eddystones.count)")
309 // [swift_Sublocation_getEddystones]
310
311 // [swift_Sublocation_getGraph]
312 // Get graph
313 let graph = sublocation.getGraph()
314 if let graph = graph {
315 demonstrateGraphUsage(graph)
316 }
317 // [swift_Sublocation_getGraph]
318
319 // [swift_Sublocation_getGraph_withTag]
320 // Get graph by tag
321 if let graphByTag = sublocation.getGraph("main") {
322 print("Found graph with tag \"main\"")
323 demonstrateGraphUsage(graphByTag)
324 }
325 // [swift_Sublocation_getGraph_withTag]
326
327 // [swift_Sublocation_getVenueById]
328 // Get venue by ID
329 if !venues.isEmpty {
330 if let venueById = sublocation.getVenueById(venues.first!.getId()) {
331 print("Found venue by ID: \‍(venueById.getId())")
332 demonstrateVenueUsage(venueById)
333 }
334 }
335 // [swift_Sublocation_getVenueById]
336
337 // [swift_Sublocation_getZoneById]
338 // Get zone by ID
339 if !zones.isEmpty {
340 if let zoneById = sublocation.getZoneById(zones.first!.getId()) {
341 print("Found zone by ID: \‍(zoneById.getId())")
342 demonstrateZoneUsage(zoneById)
343 }
344 }
345 // [swift_Sublocation_getZoneById]
346
347 // [swift_Sublocation_globalToLocal]
348 // Convert global coordinates to local coordinates
349 let globalPoint = NCGlobalPoint(lat: 55.7558, lon: 37.6176) // Moscow coordinates
350 let localPoint = sublocation.globalToLocal(globalPoint)
351 print("Global point \‍(globalPoint.getLat()), \‍(globalPoint.getLon()) converted to local: \‍(localPoint.getX()), \‍(localPoint.getY())")
352 // [swift_Sublocation_globalToLocal]
353
354 // [swift_Sublocation_localToGlobal]
355 // Convert local coordinates to global coordinates
356 let localPoint2 = NCLocationPoint(x: 100.0, y: 200.0)
357 let globalPoint2 = sublocation.localToGlobal(localPoint2)
358 print("Local point \‍(localPoint2.getX()), \‍(localPoint2.getY()) converted to global: \‍(globalPoint2.getLat()), \‍(globalPoint2.getLon())")
359 // [swift_Sublocation_localToGlobal]
360
361 // [swift_Sublocation_getImage]
362 // Get sublocation image
363 if let image = sublocation.getImage(1024) { // max texture size 1024
364 print("Sublocation image obtained with max texture size 1024")
365 }
366 // [swift_Sublocation_getImage]
367 }
368
369 /**
370 * Demonstrate Venue class methods
371 */
372 func demonstrateVenueUsage(_ venue: NCVenue) {
373 // [swift_Venue_getId]
374 // Get venue ID
375 let venueId = venue.getId()
376 print("Venue ID: \‍(venueId)")
377 // [swift_Venue_getId]
378
379 // [swift_Venue_getLocationId]
380 // Get venue location ID
381 let locationId = venue.getLocationId()
382 print("Venue location ID: \‍(locationId)")
383 // [swift_Venue_getLocationId]
384
385 // [swift_Venue_getSublocationId]
386 // Get venue sublocation ID
387 let sublocationId = venue.getSublocationId()
388 print("Venue sublocation ID: \‍(sublocationId)")
389 // [swift_Venue_getSublocationId]
390
391 // [swift_Venue_getName]
392 // Get venue name
393 let venueName = venue.getName()
394 print("Venue name: \‍(venueName ?? "nil")")
395 // [swift_Venue_getName]
396
397 // [swift_Venue_getPhone]
398 // Get venue phone
399 let phone = venue.getPhone()
400 print("Venue phone: \‍(phone ?? "nil")")
401 // [swift_Venue_getPhone]
402
403 // [swift_Venue_getDescript]
404 // Get venue description
405 let venueDescription = venue.getDescript()
406 print("Venue description: \‍(venueDescription ?? "nil")")
407 // [swift_Venue_getDescript]
408
409 // [swift_Venue_getAlias]
410 // Get venue alias
411 let alias = venue.getAlias()
412 print("Venue alias: \‍(alias ?? "nil")")
413 // [swift_Venue_getAlias]
414
415 // [swift_Venue_getCategoryId]
416 // Get category ID
417 let categoryId = venue.getCategoryId()
418 print("Venue category ID: \‍(categoryId)")
419 // [swift_Venue_getCategoryId]
420
421 // [swift_Venue_getImageUrl]
422 // Get venue image URL
423 if let imageUrl = venue.getImageUrl() {
424 print("Venue image URL: \‍(imageUrl)")
425 }
426 // [swift_Venue_getImageUrl]
427
428 // [swift_Venue_getPoint]
429 // Get venue point
430 let point = venue.getPoint()
431 if let point = point {
432 demonstratePointUsage(point)
433 }
434 // [swift_Venue_getPoint]
435 }
436
437 /**
438 * Demonstrate Zone class methods
439 */
440 func demonstrateZoneUsage(_ zone: NCZone) {
441 // [swift_Zone_getId]
442 // Get zone ID
443 let zoneId = zone.getId()
444 print("Zone ID: \‍(zoneId)")
445 // [swift_Zone_getId]
446
447 // [swift_Zone_getLocationId]
448 // Get zone location ID
449 let locationId = zone.getLocationId()
450 print("Zone location ID: \‍(locationId)")
451 // [swift_Zone_getLocationId]
452
453 // [swift_Zone_getSublocationId]
454 // Get zone sublocation ID
455 let sublocationId = zone.getSublocationId()
456 print("Zone sublocation ID: \‍(sublocationId)")
457 // [swift_Zone_getSublocationId]
458
459 // [swift_Zone_getName]
460 // Get zone name
461 let zoneName = zone.getName()
462 print("Zone name: \‍(zoneName ?? "nil")")
463 // [swift_Zone_getName]
464
465 // [swift_Zone_getDescript]
466 // Get zone description
467 let zoneDescription = zone.getDescript()
468 print("Zone description: \‍(zoneDescription ?? "nil")")
469 // [swift_Zone_getDescript]
470
471 // [swift_Zone_getCategoryId]
472 // Get category ID
473 let categoryId = zone.getCategoryId()
474 print("Zone category ID: \‍(categoryId)")
475 // [swift_Zone_getCategoryId]
476
477 // [swift_Zone_getAlias]
478 // Get zone alias
479 let alias = zone.getAlias()
480 print("Zone alias: \‍(alias ?? "nil")")
481 // [swift_Zone_getAlias]
482
483 // [swift_Zone_getColor]
484 // Get zone color
485 let color = zone.getColor()
486 print("Zone color: \‍(color ?? "nil")")
487 // [swift_Zone_getColor]
488
489 // [swift_Zone_getPolygon]
490 // Get zone polygon
491 let polygon = zone.getPolygon()
492 print("Zone polygon points: \‍(polygon.count)")
493 // [swift_Zone_getPolygon]
494 }
495
496 /**
497 * Demonstrate Beacon class methods
498 */
499 func demonstrateBeaconUsage(_ beacon: NCBeacon) {
500 // [swift_Beacon_getPoint]
501 // Get beacon point
502 let point = beacon.getPoint()
503 if let point = point {
504 demonstratePointUsage(point)
505 }
506 // [swift_Beacon_getPoint]
507
508 // [swift_Beacon_getLocationId]
509 // Get beacon location ID
510 let locationId = beacon.getLocationId()
511 print("Beacon location ID: \‍(locationId)")
512 // [swift_Beacon_getLocationId]
513
514 // [swift_Beacon_getSublocationId]
515 // Get beacon sublocation ID
516 let sublocationId = beacon.getSublocationId()
517 print("Beacon sublocation ID: \‍(sublocationId)")
518 // [swift_Beacon_getSublocationId]
519
520 // [swift_Beacon_getName]
521 // Get beacon name
522 let beaconName = beacon.getName()
523 print("Beacon name: \‍(beaconName ?? "nil")")
524 // [swift_Beacon_getName]
525
526 // [swift_Beacon_getMajor]
527 // Get beacon major
528 let major = beacon.getMajor()
529 print("Beacon major: \‍(major)")
530 // [swift_Beacon_getMajor]
531
532 // [swift_Beacon_getMinor]
533 // Get beacon minor
534 let minor = beacon.getMinor()
535 print("Beacon minor: \‍(minor)")
536 // [swift_Beacon_getMinor]
537
538 // [swift_Beacon_getUuid]
539 // Get beacon UUID
540 let uuid = beacon.getUuid()
541 print("Beacon UUID: \‍(uuid ?? "nil")")
542 // [swift_Beacon_getUuid]
543
544 // [swift_Beacon_getPower]
545 // Get beacon power
546 let power = beacon.getPower()
547 if let power = power {
548 print("Beacon power: \‍(power)")
549 }
550 // [swift_Beacon_getPower]
551
552 // [swift_Beacon_getStatus]
553 // Get beacon status
554 let status = beacon.getStatus()
555 print("Beacon status: \‍(status)")
556 // [swift_Beacon_getStatus]
557 }
558
559 /**
560 * Demonstrate Wifi class methods
561 */
562 func demonstrateWifiUsage(_ wifi: NCWifi) {
563 // [swift_Wifi_getPoint]
564 // Get WiFi point
565 let point = wifi.getPoint()
566 if let point = point {
567 demonstratePointUsage(point)
568 }
569 // [swift_Wifi_getPoint]
570
571 // [swift_Wifi_getLocationId]
572 // Get WiFi location ID
573 let locationId = wifi.getLocationId()
574 print("WiFi location ID: \‍(locationId)")
575 // [swift_Wifi_getLocationId]
576
577 // [swift_Wifi_getSublocationId]
578 // Get WiFi sublocation ID
579 let sublocationId = wifi.getSublocationId()
580 print("WiFi sublocation ID: \‍(sublocationId)")
581 // [swift_Wifi_getSublocationId]
582
583 // [swift_Wifi_getName]
584 // Get WiFi name
585 let wifiName = wifi.getName()
586 print("WiFi name: \‍(wifiName ?? "nil")")
587 // [swift_Wifi_getName]
588
589 // [swift_Wifi_getMac]
590 // Get WiFi MAC address
591 let mac = wifi.getMac()
592 print("WiFi MAC: \‍(mac ?? "nil")")
593 // [swift_Wifi_getMac]
594
595 // [swift_Wifi_getStatus]
596 // Get WiFi status
597 let status = wifi.getStatus()
598 print("WiFi status: \‍(status)")
599 // [swift_Wifi_getStatus]
600 }
601
602 /**
603 * Demonstrate Eddystone class methods
604 */
605 func demonstrateEddystoneUsage(_ eddystone: NCEddystone) {
606 // [swift_Eddystone_getPoint]
607 // Get Eddystone point
608 let point = eddystone.getPoint()
609 if let point = point {
610 demonstratePointUsage(point)
611 }
612 // [swift_Eddystone_getPoint]
613
614 // [swift_Eddystone_getLocationId]
615 // Get Eddystone location ID
616 let locationId = eddystone.getLocationId()
617 print("Eddystone location ID: \‍(locationId)")
618 // [swift_Eddystone_getLocationId]
619
620 // [swift_Eddystone_getSublocationId]
621 // Get Eddystone sublocation ID
622 let sublocationId = eddystone.getSublocationId()
623 print("Eddystone sublocation ID: \‍(sublocationId)")
624 // [swift_Eddystone_getSublocationId]
625
626 // [swift_Eddystone_getName]
627 // Get Eddystone name
628 let eddystoneName = eddystone.getName()
629 print("Eddystone name: \‍(eddystoneName ?? "nil")")
630 // [swift_Eddystone_getName]
631
632 // [swift_Eddystone_getNamespaceId]
633 // Get Eddystone namespace ID
634 let namespaceId = eddystone.getNamespaceId()
635 print("Eddystone namespace ID: \‍(namespaceId ?? "nil")")
636 // [swift_Eddystone_getNamespaceId]
637
638 // [swift_Eddystone_getInstanceId]
639 // Get Eddystone instance ID
640 let instanceId = eddystone.getInstanceId()
641 print("Eddystone instance ID: \‍(instanceId ?? "nil")")
642 // [swift_Eddystone_getInstanceId]
643
644 // [swift_Eddystone_getPower]
645 // Get Eddystone power
646 let power = eddystone.getPower()
647 if let power = power {
648 print("Eddystone power: \‍(power)")
649 }
650 // [swift_Eddystone_getPower]
651
652 // [swift_Eddystone_getStatus]
653 // Get Eddystone status
654 let status = eddystone.getStatus()
655 print("Eddystone status: \‍(status)")
656 // [swift_Eddystone_getStatus]
657 }
658
659 /**
660 * Demonstrate Point class methods
661 */
662 func demonstratePointUsage(_ point: NCPoint) {
663 // [swift_Point_getX]
664 // Get X coordinate
665 let x = point.getX()
666 print("Point X: \‍(x)")
667 // [swift_Point_getX]
668
669 // [swift_Point_getY]
670 // Get Y coordinate
671 let y = point.getY()
672 print("Point Y: \‍(y)")
673 // [swift_Point_getY]
674 }
675
676 /**
677 * Demonstrate Graph class methods
678 */
679 func demonstrateGraphUsage(_ graph: NCGraph) {
680 // [swift_Graph_getVertices]
681 // Get graph vertices
682 let vertices = graph.getVertices()
683 print("Number of graph vertices: \‍(vertices.count)")
684 // [swift_Graph_getVertices]
685
686 // [swift_Graph_getEdges]
687 // Get graph edges
688 let edges = graph.getEdges()
689 print("Number of graph edges: \‍(edges.count)")
690 // [swift_Graph_getEdges]
691 }
692
693 /**
694 * Demonstrate GraphVertex class methods
695 */
696 func demonstrateGraphVertexUsage(_ vertex: NCGraphVertex) {
697 // [swift_GraphVertex_getId]
698 // Get vertex ID
699 let vertexId = vertex.getId()
700 print("Vertex ID: \‍(vertexId)")
701 // [swift_GraphVertex_getId]
702
703 // [swift_GraphVertex_getPoint]
704 // Get vertex point
705 let point = vertex.getPoint()
706 if let point = point {
707 demonstratePointUsage(point)
708 }
709 // [swift_GraphVertex_getPoint]
710
711 // [swift_GraphVertex_getName]
712 // Get vertex name
713 let name = vertex.getName()
714 print("Vertex name: \‍(name ?? "nil")")
715 // [swift_GraphVertex_getName]
716
717 // [swift_GraphVertex_getIsExternal]
718 // Get vertex external flag
719 let isExternal = vertex.getIsExternal()
720 print("Vertex is external: \‍(isExternal)")
721 // [swift_GraphVertex_getIsExternal]
722
723 // [swift_GraphVertex_getIsElevation]
724 // Get vertex elevation flag
725 let isElevation = vertex.getIsElevation()
726 print("Vertex is elevation: \‍(isElevation)")
727 // [swift_GraphVertex_getIsElevation]
728 }
729
730 /**
731 * Demonstrate GraphEdge class methods
732 */
733 func demonstrateGraphEdgeUsage(_ edge: NCGraphEdge) {
734 // [swift_GraphEdge_getWeight]
735 // Get edge weight
736 let weight = edge.getWeight()
737 print("Edge weight: \‍(weight)")
738 // [swift_GraphEdge_getWeight]
739
740 // [swift_GraphEdge_getDst]
741 // Get destination vertex ID
742 let dst = edge.getDst()
743 print("Edge destination ID: \‍(dst)")
744 // [swift_GraphEdge_getDst]
745
746 // [swift_GraphEdge_getSrc]
747 // Get source vertex ID
748 let src = edge.getSrc()
749 print("Edge source ID: \‍(src)")
750 // [swift_GraphEdge_getSrc]
751
752 // [swift_GraphEdge_getWeightCoef]
753 // Get edge weight coefficient
754 let weightCoef = edge.getWeightCoef()
755 print("Edge weight coefficient: \‍(weightCoef)")
756 // [swift_GraphEdge_getWeightCoef]
757 }
758
759 /**
760 * Demonstrate ElevationGraph class methods
761 */
762 func demonstrateElevationGraphUsage(_ elevationGraph: NCElevationGraph) {
763 // [swift_ElevationGraph_getEdges]
764 // Get elevation graph edges
765 let edges = elevationGraph.getEdges()
766 print("Number of elevation graph edges: \‍(edges.count)")
767
768 // Demonstrate each edge
769 for (index, edge) in edges.enumerated() {
770 print("Elevation graph edge \‍(index + 1):")
771 demonstrateGraphEdgeUsage(edge)
772 }
773 // [swift_ElevationGraph_getEdges]
774 }
775
776 /**
777 * Demonstrate TransmitterStatus enum
778 */
779 func demonstrateTransmitterStatus() {
780 // [swift_TransmitterStatus_values]
781 // Get all transmitter status values
782 print("Available transmitter statuses:")
783 print(" - NCTransmitterStatusActive: \‍(NCTransmitterStatusActive)")
784 print(" - NCTransmitterStatusInactive: \‍(NCTransmitterStatusInactive)")
785 // [swift_TransmitterStatus_values]
786 }
787
788 /**
789 * Clean up resources
790 */
791 func cleanup() {
792 if let manager = locationManager {
793 // [swift_LocationManager_removeLocationListener]
794 // Remove location listener
795 manager.removeLocationListener(self)
796 // [swift_LocationManager_removeLocationListener]
797 }
798 }
799
800 /**
801 * Main demonstration method
802 */
803 func runExample() {
804 print("=== LocationManager Example ===")
805
806 demonstrateLocationManagerMethods()
807 demonstrateTransmitterStatus()
808
809 // Wait a bit for location to load
810 Thread.sleep(forTimeInterval: 2.0)
811
812 cleanup()
813 print("=== Example completed ===")
814 }
815}
816
817// MARK: - NCLocationListener
818
819extension LocationManagerExample {
820 // [swift_LocationListener_onLocationLoaded]
821 func onLocationLoaded(_ location: NCLocation?) {
822 print("Location loaded successfully")
823 currentLocation = location
824 if let location = location {
825 demonstrateLocationUsage(location)
826 }
827 }
828 // [swift_LocationListener_onLocationLoaded]
829
830 // [swift_LocationListener_onLocationUploaded]
831 func onLocationUploaded(_ locationId: Int32) {
832 print("Location uploaded: \‍(locationId)")
833 }
834 // [swift_LocationListener_onLocationUploaded]
835
836 // [swift_LocationListener_onLocationFailed]
837 func onLocationFailed(_ locationId: Int32, error: Error?) {
838 print("Failed to load location \‍(locationId): \‍(error?.localizedDescription ?? "Unknown error")")
839 }
840 // [swift_LocationListener_onLocationFailed]
841}
842
843/**
844 * Function to run the example
845 */
846func main() {
847 let example = LocationManagerExample()
848 example.runExample()
849}
850
851// Run the example
852main()