Loading...
Searching...
No Matches
LocationManagerExample.kt
Go to the documentation of this file.
1package com.navigine.examples
2
3import com.navigine.idl.java.*
4
5/**
6 * LocationManager usage example for Kotlin
7 * Demonstrates working with locations, sublocations, categories, and other location-related classes
8 */
9class LocationManagerExample {
10 private var sdk: NavigineSdk? = null
11 private var locationManager: LocationManager? = null
12 private var currentLocation: Location? = null
13 private var locationListener: LocationListener? = null
14
15 init {
16 initializeSdk()
17 setupLocationListener()
18 }
19
20 /**
21 * Initialize SDK and get LocationManager
22 */
23 private fun initializeSdk() {
24 try {
25 // [kotlin_NavigineSdk_getInstance]
26 // Get SDK instance
27 sdk = NavigineSdk.getInstance()
28 // [kotlin_NavigineSdk_getInstance]
29
30 // [kotlin_NavigineSdk_setUserHash]
31 // Set user hash
32 sdk?.setUserHash("USER-HASH-HERE")
33 // [kotlin_NavigineSdk_setUserHash]
34
35 // [kotlin_NavigineSdk_setServer]
36 // Set server URL (optional)
37 sdk?.setServer("https://custom.navigine.com")
38 // [kotlin_NavigineSdk_setServer]
39
40 // [kotlin_NavigineSdk_getLocationManager]
41 // Get LocationManager for working with locations
42 locationManager = sdk?.getLocationManager()
43 // [kotlin_NavigineSdk_getLocationManager]
44
45 if (locationManager != null) {
46 println("LocationManager successfully initialized")
47 }
48 } catch (e: Exception) {
49 System.err.println("Error initializing SDK: ${e.message}")
50 }
51 }
52
53 /**
54 * Setup location listener
55 */
56 private fun setupLocationListener() {
57 locationListener = object : LocationListener() {
58 override
59 // [kotlin_LocationListener_onLocationLoaded]
60 fun onLocationLoaded(location: Location?) {
61 println("Location loaded successfully")
62 currentLocation = location
63 location?.let { demonstrateLocationUsage(it) }
64 }
65 // [kotlin_LocationListener_onLocationLoaded]
66
67 override
68 // [kotlin_LocationListener_onLocationUploaded]
69 fun onLocationUploaded(locationId: Int) {
70 println("Location uploaded: $locationId")
71 }
72 // [kotlin_LocationListener_onLocationUploaded]
73
74 override
75 // [kotlin_LocationListener_onLocationFailed]
76 fun onLocationFailed(locationId: Int, error: Error) {
77 System.err.println("Failed to load location $locationId: ${error.message}")
78 }
79 // [kotlin_LocationListener_onLocationFailed]
80 }
81 }
82
83 /**
84 * Demonstrate LocationManager methods
85 */
86 fun demonstrateLocationManagerMethods() {
87 val manager = locationManager ?: run {
88 System.err.println("LocationManager not initialized")
89 return
90 }
91
92 val listener = locationListener ?: return
93
94 // [kotlin_LocationManager_addLocationListener]
95 // Add location listener
96 manager.addLocationListener(listener)
97 // [kotlin_LocationManager_addLocationListener]
98
99 // [kotlin_LocationManager_setLocationId]
100 // Set location ID to load
101 manager.setLocationId(12345)
102 // [kotlin_LocationManager_setLocationId]
103
104 // [kotlin_LocationManager_getLocationId]
105 // Get current location ID
106 val currentLocationId = manager.getLocationId()
107 println("Current location ID: $currentLocationId")
108 // [kotlin_LocationManager_getLocationId]
109
110 // [kotlin_LocationManager_setLocationUpdateInterval]
111 // Set location update interval (in seconds)
112 manager.setLocationUpdateInterval(600) // 10 minutes
113 // [kotlin_LocationManager_setLocationUpdateInterval]
114
115 // [kotlin_LocationManager_commitChanges]
116 // Commit changes
117 manager.commitChanges()
118 // [kotlin_LocationManager_commitChanges]
119
120 // [kotlin_LocationManager_revertChanges]
121 // Revert changes (if needed)
122 // manager.revertChanges()
123 // [kotlin_LocationManager_revertChanges]
124 }
125
126 /**
127 * Demonstrate Location class methods
128 */
129 fun demonstrateLocationUsage(location: Location) {
130 // [kotlin_Location_getId]
131 // Get location ID
132 val locationId = location.id
133 println("Location ID: $locationId")
134 // [kotlin_Location_getId]
135
136 // [kotlin_Location_getVersion]
137 // Get location version
138 val version = location.version
139 println("Location version: $version")
140 // [kotlin_Location_getVersion]
141
142 // [kotlin_Location_getName]
143 // Get location name
144 val name = location.name
145 println("Location name: $name")
146 // [kotlin_Location_getName]
147
148 // [kotlin_Location_getDescript]
149 // Get location description
150 val description = location.descript
151 println("Location description: $description")
152 // [kotlin_Location_getDescript]
153
154 // [kotlin_Location_getModified]
155 // Check if location is modified
156 val isModified = location.modified
157 println("Location modified: $isModified")
158 // [kotlin_Location_getModified]
159
160 // [kotlin_Location_getGraphTags]
161 // Get available graph tags
162 val graphTags = location.graphTags
163 println("Available graph tags: $graphTags")
164 // [kotlin_Location_getGraphTags]
165
166 // [kotlin_Location_getElevationGraph]
167 // Get elevation graph by tag
168 graphTags.firstOrNull()?.let { tag ->
169 val elevationGraph = location.getElevationGraph(tag)
170 elevationGraph?.let { demonstrateElevationGraphUsage(it) }
171 }
172 // [kotlin_Location_getElevationGraph]
173
174 // [kotlin_Location_getCategories]
175 // Get all categories
176 val categories = location.categories
177 println("Number of categories: ${categories.size}")
178 // [kotlin_Location_getCategories]
179
180 // [kotlin_Location_getCategoryById]
181 // Get category by ID
182 categories.firstOrNull()?.let { category ->
183 val foundCategory = location.getCategoryById(category.id)
184 foundCategory?.let { demonstrateCategoryUsage(it) }
185 }
186 // [kotlin_Location_getCategoryById]
187
188 // [kotlin_Location_getSublocations]
189 // Get all sublocations
190 val sublocations = location.sublocations
191 println("Number of sublocations: ${sublocations.size}")
192 // [kotlin_Location_getSublocations]
193
194 // [kotlin_Location_getSublocationById]
195 // Get sublocation by ID
196 sublocations.firstOrNull()?.let { sublocation ->
197 val foundSublocation = location.getSublocationById(sublocation.id)
198 foundSublocation?.let { demonstrateSublocationUsage(it) }
199 }
200 // [kotlin_Location_getSublocationById]
201 }
202
203 /**
204 * Demonstrate Category class methods
205 */
206 fun demonstrateCategoryUsage(category: Category) {
207 // [kotlin_Category_getId]
208 // Get category ID
209 val categoryId = category.id
210 println("Category ID: $categoryId")
211 // [kotlin_Category_getId]
212
213 // [kotlin_Category_getName]
214 // Get category name
215 val categoryName = category.name
216 println("Category name: $categoryName")
217 // [kotlin_Category_getName]
218
219 // [kotlin_Category_getImageUrl]
220 // Get category image URL
221 val imageUrl = category.imageUrl
222 imageUrl?.let { println("Category image URL: $it") }
223 // [kotlin_Category_getImageUrl]
224 }
225
226 /**
227 * Demonstrate Sublocation class methods
228 */
229 fun demonstrateSublocationUsage(sublocation: Sublocation) {
230 // [kotlin_Sublocation_getId]
231 // Get sublocation ID
232 val sublocationId = sublocation.id
233 println("Sublocation ID: $sublocationId")
234 // [kotlin_Sublocation_getId]
235
236 // [kotlin_Sublocation_getName]
237 // Get sublocation name
238 val sublocationName = sublocation.name
239 println("Sublocation name: $sublocationName")
240 // [kotlin_Sublocation_getName]
241
242 // [kotlin_Sublocation_getDescript]
243 // Get sublocation description
244 val sublocationDescription = sublocation.descript
245 println("Sublocation description: $sublocationDescription")
246 // [kotlin_Sublocation_getDescript]
247
248 // [kotlin_Sublocation_getCategoryId]
249 // Get category ID
250 val categoryId = sublocation.categoryId
251 println("Sublocation category ID: $categoryId")
252 // [kotlin_Sublocation_getCategoryId]
253
254 // [kotlin_Sublocation_getLocation]
255 // Get location ID
256 val locationId = sublocation.location
257 println("Sublocation location ID: $locationId")
258 // [kotlin_Sublocation_getLocation]
259
260 // [kotlin_Sublocation_getWidth]
261 // Get sublocation width in meters
262 val width = sublocation.width
263 println("Sublocation width: $width meters")
264 // [kotlin_Sublocation_getWidth]
265
266 // [kotlin_Sublocation_getHeight]
267 // Get sublocation height in meters
268 val height = sublocation.height
269 println("Sublocation height: $height meters")
270 // [kotlin_Sublocation_getHeight]
271
272 // [kotlin_Sublocation_getAltitude]
273 // Get sublocation altitude in meters
274 val altitude = sublocation.altitude
275 altitude?.let { println("Sublocation altitude: $it meters") }
276 // [kotlin_Sublocation_getAltitude]
277
278 // [kotlin_Sublocation_getAzimuth]
279 // Get sublocation azimuth in degrees
280 val azimuth = sublocation.azimuth
281 println("Sublocation azimuth: $azimuth degrees")
282 // [kotlin_Sublocation_getAzimuth]
283
284 // [kotlin_Sublocation_getOriginPoint]
285 // Get sublocation origin point in WGS84 coordinates
286 val originPoint = sublocation.originPoint
287 println("Sublocation origin point: ${originPoint.lat}, ${originPoint.lon}")
288 // [kotlin_Sublocation_getOriginPoint]
289
290 // [kotlin_Sublocation_getLevelId]
291 // Get sublocation level ID
292 val levelId = sublocation.levelId
293 println("Sublocation level ID: $levelId")
294 // [kotlin_Sublocation_getLevelId]
295
296 // [kotlin_Sublocation_getExternalId]
297 // Get sublocation external ID
298 val externalId = sublocation.externalId
299 println("Sublocation external ID: $externalId")
300 // [kotlin_Sublocation_getExternalId]
301
302 // [kotlin_Sublocation_getBuildingName]
303 // Get sublocation building name
304 val buildingName = sublocation.buildingName
305 println("Sublocation building name: $buildingName")
306 // [kotlin_Sublocation_getBuildingName]
307
308 // [kotlin_Sublocation_getReferencePoints]
309 // Get reference points
310 val referencePoints = sublocation.referencePoints
311 println("Number of reference points: ${referencePoints.size}")
312 // [kotlin_Sublocation_getReferencePoints]
313
314 // [kotlin_Sublocation_getVenues]
315 // Get venues
316 val venues = sublocation.venues
317 println("Number of venues: ${venues.size}")
318 // [kotlin_Sublocation_getVenues]
319
320 // [kotlin_Sublocation_getZones]
321 // Get zones
322 val zones = sublocation.zones
323 println("Number of zones: ${zones.size}")
324 // [kotlin_Sublocation_getZones]
325
326 // [kotlin_Sublocation_getBeacons]
327 // Get beacons
328 val beacons = sublocation.beacons
329 println("Number of beacons: ${beacons.size}")
330 // [kotlin_Sublocation_getBeacons]
331
332 // [kotlin_Sublocation_getWifis]
333 // Get WiFi access points
334 val wifis = sublocation.wifis
335 println("Number of WiFi access points: ${wifis.size}")
336 // [kotlin_Sublocation_getWifis]
337
338 // [kotlin_Sublocation_getEddystones]
339 // Get Eddystone beacons
340 val eddystones = sublocation.eddystones
341 println("Number of Eddystone beacons: ${eddystones.size}")
342 // [kotlin_Sublocation_getEddystones]
343
344 // [kotlin_Sublocation_getGraph]
345 // Get graph
346 val graph = sublocation.graph
347 graph?.let { demonstrateGraphUsage(it) }
348 // [kotlin_Sublocation_getGraph]
349
350 // [kotlin_Sublocation_getGraph_withTag]
351 // Get graph by tag
352 val graphByTag = sublocation.getGraph("main")
353 graphByTag?.let {
354 println("Found graph with tag \"main\"")
355 demonstrateGraphUsage(it)
356 }
357 // [kotlin_Sublocation_getGraph_withTag]
358
359 // [kotlin_Sublocation_getVenueById]
360 // Get venue by ID
361 if (venues.isNotEmpty()) {
362 val venueById = sublocation.getVenueById(venues.first().id)
363 venueById?.let {
364 println("Found venue by ID: ${it.id}")
365 demonstrateVenueUsage(it)
366 }
367 }
368 // [kotlin_Sublocation_getVenueById]
369
370 // [kotlin_Sublocation_getZoneById]
371 // Get zone by ID
372 if (zones.isNotEmpty()) {
373 val zoneById = sublocation.getZoneById(zones.first().id)
374 zoneById?.let {
375 println("Found zone by ID: ${it.id}")
376 demonstrateZoneUsage(it)
377 }
378 }
379 // [kotlin_Sublocation_getZoneById]
380
381 // [kotlin_Sublocation_globalToLocal]
382 // Convert global coordinates to local coordinates
383 val globalPoint = GlobalPoint(55.7558, 37.6176) // Moscow coordinates
384 val localPoint = sublocation.globalToLocal(globalPoint)
385 println("Global point ${globalPoint.lat}, ${globalPoint.lon} converted to local: ${localPoint.x}, ${localPoint.y}")
386 // [kotlin_Sublocation_globalToLocal]
387
388 // [kotlin_Sublocation_localToGlobal]
389 // Convert local coordinates to global coordinates
390 val localPoint2 = LocationPoint(100.0, 200.0)
391 val globalPoint2 = sublocation.localToGlobal(localPoint2)
392 println("Local point ${localPoint2.x}, ${localPoint2.y} converted to global: ${globalPoint2.lat}, ${globalPoint2.lon}")
393 // [kotlin_Sublocation_localToGlobal]
394
395 // [kotlin_Sublocation_getImage]
396 // Get sublocation image
397 val image = sublocation.getImage(1024) // max texture size 1024
398 image?.let { println("Sublocation image obtained with max texture size 1024") }
399 // [kotlin_Sublocation_getImage]
400 }
401
402 /**
403 * Demonstrate Venue class methods
404 */
405 fun demonstrateVenueUsage(venue: Venue) {
406 // [kotlin_Venue_getId]
407 // Get venue ID
408 val venueId = venue.id
409 println("Venue ID: $venueId")
410 // [kotlin_Venue_getId]
411
412 // [kotlin_Venue_getLocationId]
413 // Get venue location ID
414 val locationId = venue.locationId
415 println("Venue location ID: $locationId")
416 // [kotlin_Venue_getLocationId]
417
418 // [kotlin_Venue_getSublocationId]
419 // Get venue sublocation ID
420 val sublocationId = venue.sublocationId
421 println("Venue sublocation ID: $sublocationId")
422 // [kotlin_Venue_getSublocationId]
423
424 // [kotlin_Venue_getName]
425 // Get venue name
426 val venueName = venue.name
427 println("Venue name: $venueName")
428 // [kotlin_Venue_getName]
429
430 // [kotlin_Venue_getPhone]
431 // Get venue phone
432 val phone = venue.phone
433 println("Venue phone: $phone")
434 // [kotlin_Venue_getPhone]
435
436 // [kotlin_Venue_getDescript]
437 // Get venue description
438 val venueDescription = venue.descript
439 println("Venue description: $venueDescription")
440 // [kotlin_Venue_getDescript]
441
442 // [kotlin_Venue_getAlias]
443 // Get venue alias
444 val alias = venue.alias
445 println("Venue alias: $alias")
446 // [kotlin_Venue_getAlias]
447
448 // [kotlin_Venue_getCategoryId]
449 // Get category ID
450 val categoryId = venue.categoryId
451 println("Venue category ID: $categoryId")
452 // [kotlin_Venue_getCategoryId]
453
454 // [kotlin_Venue_getImageUrl]
455 // Get venue image URL
456 val imageUrl = venue.imageUrl
457 imageUrl?.let { println("Venue image URL: $it") }
458 // [kotlin_Venue_getImageUrl]
459
460 // [kotlin_Venue_getPoint]
461 // Get venue point
462 val point = venue.point
463 point?.let { demonstratePointUsage(it) }
464 // [kotlin_Venue_getPoint]
465 }
466
467 /**
468 * Demonstrate Zone class methods
469 */
470 fun demonstrateZoneUsage(zone: Zone) {
471 // [kotlin_Zone_getId]
472 // Get zone ID
473 val zoneId = zone.id
474 println("Zone ID: $zoneId")
475 // [kotlin_Zone_getId]
476
477 // [kotlin_Zone_getLocationId]
478 // Get zone location ID
479 val locationId = zone.locationId
480 println("Zone location ID: $locationId")
481 // [kotlin_Zone_getLocationId]
482
483 // [kotlin_Zone_getSublocationId]
484 // Get zone sublocation ID
485 val sublocationId = zone.sublocationId
486 println("Zone sublocation ID: $sublocationId")
487 // [kotlin_Zone_getSublocationId]
488
489 // [kotlin_Zone_getName]
490 // Get zone name
491 val zoneName = zone.name
492 println("Zone name: $zoneName")
493 // [kotlin_Zone_getName]
494
495 // [kotlin_Zone_getDescript]
496 // Get zone description
497 val zoneDescription = zone.descript
498 println("Zone description: $zoneDescription")
499 // [kotlin_Zone_getDescript]
500
501 // [kotlin_Zone_getCategoryId]
502 // Get category ID
503 val categoryId = zone.categoryId
504 println("Zone category ID: $categoryId")
505 // [kotlin_Zone_getCategoryId]
506
507 // [kotlin_Zone_getAlias]
508 // Get zone alias
509 val alias = zone.alias
510 println("Zone alias: $alias")
511 // [kotlin_Zone_getAlias]
512
513 // [kotlin_Zone_getColor]
514 // Get zone color
515 val color = zone.color
516 println("Zone color: $color")
517 // [kotlin_Zone_getColor]
518
519 // [kotlin_Zone_getPolygon]
520 // Get zone polygon
521 val polygon = zone.polygon
522 println("Zone polygon points: ${polygon.size}")
523 // [kotlin_Zone_getPolygon]
524 }
525
526 /**
527 * Demonstrate Beacon class methods
528 */
529 fun demonstrateBeaconUsage(beacon: Beacon) {
530 // [kotlin_Beacon_getPoint]
531 // Get beacon point
532 val point = beacon.point
533 point?.let { demonstratePointUsage(it) }
534 // [kotlin_Beacon_getPoint]
535
536 // [kotlin_Beacon_getLocationId]
537 // Get beacon location ID
538 val locationId = beacon.locationId
539 println("Beacon location ID: $locationId")
540 // [kotlin_Beacon_getLocationId]
541
542 // [kotlin_Beacon_getSublocationId]
543 // Get beacon sublocation ID
544 val sublocationId = beacon.sublocationId
545 println("Beacon sublocation ID: $sublocationId")
546 // [kotlin_Beacon_getSublocationId]
547
548 // [kotlin_Beacon_getName]
549 // Get beacon name
550 val beaconName = beacon.name
551 println("Beacon name: $beaconName")
552 // [kotlin_Beacon_getName]
553
554 // [kotlin_Beacon_getMajor]
555 // Get beacon major
556 val major = beacon.major
557 println("Beacon major: $major")
558 // [kotlin_Beacon_getMajor]
559
560 // [kotlin_Beacon_getMinor]
561 // Get beacon minor
562 val minor = beacon.minor
563 println("Beacon minor: $minor")
564 // [kotlin_Beacon_getMinor]
565
566 // [kotlin_Beacon_getUuid]
567 // Get beacon UUID
568 val uuid = beacon.uuid
569 println("Beacon UUID: $uuid")
570 // [kotlin_Beacon_getUuid]
571
572 // [kotlin_Beacon_getPower]
573 // Get beacon power
574 val power = beacon.power
575 power?.let { println("Beacon power: $it") }
576 // [kotlin_Beacon_getPower]
577
578 // [kotlin_Beacon_getStatus]
579 // Get beacon status
580 val status = beacon.status
581 println("Beacon status: $status")
582 // [kotlin_Beacon_getStatus]
583 }
584
585 /**
586 * Demonstrate Wifi class methods
587 */
588 fun demonstrateWifiUsage(wifi: Wifi) {
589 // [kotlin_Wifi_getPoint]
590 // Get WiFi point
591 val point = wifi.point
592 point?.let { demonstratePointUsage(it) }
593 // [kotlin_Wifi_getPoint]
594
595 // [kotlin_Wifi_getLocationId]
596 // Get WiFi location ID
597 val locationId = wifi.locationId
598 println("WiFi location ID: $locationId")
599 // [kotlin_Wifi_getLocationId]
600
601 // [kotlin_Wifi_getSublocationId]
602 // Get WiFi sublocation ID
603 val sublocationId = wifi.sublocationId
604 println("WiFi sublocation ID: $sublocationId")
605 // [kotlin_Wifi_getSublocationId]
606
607 // [kotlin_Wifi_getName]
608 // Get WiFi name
609 val wifiName = wifi.name
610 println("WiFi name: $wifiName")
611 // [kotlin_Wifi_getName]
612
613 // [kotlin_Wifi_getMac]
614 // Get WiFi MAC address
615 val mac = wifi.mac
616 println("WiFi MAC: $mac")
617 // [kotlin_Wifi_getMac]
618
619 // [kotlin_Wifi_getStatus]
620 // Get WiFi status
621 val status = wifi.status
622 println("WiFi status: $status")
623 // [kotlin_Wifi_getStatus]
624 }
625
626 /**
627 * Demonstrate Eddystone class methods
628 */
629 fun demonstrateEddystoneUsage(eddystone: Eddystone) {
630 // [kotlin_Eddystone_getPoint]
631 // Get Eddystone point
632 val point = eddystone.point
633 point?.let { demonstratePointUsage(it) }
634 // [kotlin_Eddystone_getPoint]
635
636 // [kotlin_Eddystone_getLocationId]
637 // Get Eddystone location ID
638 val locationId = eddystone.locationId
639 println("Eddystone location ID: $locationId")
640 // [kotlin_Eddystone_getLocationId]
641
642 // [kotlin_Eddystone_getSublocationId]
643 // Get Eddystone sublocation ID
644 val sublocationId = eddystone.sublocationId
645 println("Eddystone sublocation ID: $sublocationId")
646 // [kotlin_Eddystone_getSublocationId]
647
648 // [kotlin_Eddystone_getName]
649 // Get Eddystone name
650 val eddystoneName = eddystone.name
651 println("Eddystone name: $eddystoneName")
652 // [kotlin_Eddystone_getName]
653
654 // [kotlin_Eddystone_getNamespaceId]
655 // Get Eddystone namespace ID
656 val namespaceId = eddystone.namespaceId
657 println("Eddystone namespace ID: $namespaceId")
658 // [kotlin_Eddystone_getNamespaceId]
659
660 // [kotlin_Eddystone_getInstanceId]
661 // Get Eddystone instance ID
662 val instanceId = eddystone.instanceId
663 println("Eddystone instance ID: $instanceId")
664 // [kotlin_Eddystone_getInstanceId]
665
666 // [kotlin_Eddystone_getPower]
667 // Get Eddystone power
668 val power = eddystone.power
669 power?.let { println("Eddystone power: $it") }
670 // [kotlin_Eddystone_getPower]
671
672 // [kotlin_Eddystone_getStatus]
673 // Get Eddystone status
674 val status = eddystone.status
675 println("Eddystone status: $status")
676 // [kotlin_Eddystone_getStatus]
677 }
678
679 /**
680 * Demonstrate Point class methods
681 */
682 fun demonstratePointUsage(point: Point) {
683 // [kotlin_Point_getX]
684 // Get X coordinate
685 val x = point.x
686 println("Point X: $x")
687 // [kotlin_Point_getX]
688
689 // [kotlin_Point_getY]
690 // Get Y coordinate
691 val y = point.y
692 println("Point Y: $y")
693 // [kotlin_Point_getY]
694 }
695
696 /**
697 * Demonstrate Graph class methods
698 */
699 fun demonstrateGraphUsage(graph: Graph) {
700 // [kotlin_Graph_getVertices]
701 // Get graph vertices
702 val vertices = graph.vertices
703 println("Number of graph vertices: ${vertices.size}")
704 // [kotlin_Graph_getVertices]
705
706 // [kotlin_Graph_getEdges]
707 // Get graph edges
708 val edges = graph.edges
709 println("Number of graph edges: ${edges.size}")
710 // [kotlin_Graph_getEdges]
711 }
712
713 /**
714 * Demonstrate GraphVertex class methods
715 */
716 fun demonstrateGraphVertexUsage(vertex: GraphVertex) {
717 // [kotlin_GraphVertex_getId]
718 // Get vertex ID
719 val vertexId = vertex.id
720 println("Vertex ID: $vertexId")
721 // [kotlin_GraphVertex_getId]
722
723 // [kotlin_GraphVertex_getPoint]
724 // Get vertex point
725 val point = vertex.point
726 point?.let { demonstratePointUsage(it) }
727 // [kotlin_GraphVertex_getPoint]
728
729 // [kotlin_GraphVertex_getName]
730 // Get vertex name
731 val name = vertex.name
732 println("Vertex name: $name")
733 // [kotlin_GraphVertex_getName]
734
735 // [kotlin_GraphVertex_getIsExternal]
736 // Get vertex external flag
737 val isExternal = vertex.isExternal
738 println("Vertex is external: $isExternal")
739 // [kotlin_GraphVertex_getIsExternal]
740
741 // [kotlin_GraphVertex_getIsElevation]
742 // Get vertex elevation flag
743 val isElevation = vertex.isElevation
744 println("Vertex is elevation: $isElevation")
745 // [kotlin_GraphVertex_getIsElevation]
746 }
747
748 /**
749 * Demonstrate GraphEdge class methods
750 */
751 fun demonstrateGraphEdgeUsage(edge: GraphEdge) {
752 // [kotlin_GraphEdge_getWeight]
753 // Get edge weight
754 val weight = edge.weight
755 println("Edge weight: $weight")
756 // [kotlin_GraphEdge_getWeight]
757
758 // [kotlin_GraphEdge_getDst]
759 // Get destination vertex ID
760 val dst = edge.dst
761 println("Edge destination ID: $dst")
762 // [kotlin_GraphEdge_getDst]
763
764 // [kotlin_GraphEdge_getSrc]
765 // Get source vertex ID
766 val src = edge.src
767 println("Edge source ID: $src")
768 // [kotlin_GraphEdge_getSrc]
769
770 // [kotlin_GraphEdge_getWeightCoef]
771 // Get edge weight coefficient
772 val weightCoef = edge.weightCoef
773 println("Edge weight coefficient: $weightCoef")
774 // [kotlin_GraphEdge_getWeightCoef]
775 }
776
777 /**
778 * Demonstrate ElevationGraph class methods
779 */
780 fun demonstrateElevationGraphUsage(elevationGraph: ElevationGraph) {
781 // [kotlin_ElevationGraph_getEdges]
782 // Get elevation graph edges
783 val edges = elevationGraph.edges
784 println("Number of elevation graph edges: ${edges.size}")
785
786 // Demonstrate each edge
787 edges.forEachIndexed { index, edge ->
788 println("Elevation graph edge ${index + 1}:")
789 demonstrateGraphEdgeUsage(edge)
790 }
791 // [kotlin_ElevationGraph_getEdges]
792 }
793
794 /**
795 * Demonstrate TransmitterStatus enum
796 */
797 fun demonstrateTransmitterStatus() {
798 // [kotlin_TransmitterStatus_values]
799 // Get all transmitter status values
800 val statuses = TransmitterStatus.values()
801 println("Available transmitter statuses:")
802 statuses.forEach { status ->
803 println(" - $status")
804 }
805 // [kotlin_TransmitterStatus_values]
806 }
807
808 /**
809 * Clean up resources
810 */
811 fun cleanup() {
812 locationManager?.let { manager ->
813 locationListener?.let { listener ->
814 // [kotlin_LocationManager_removeLocationListener]
815 // Remove location listener
816 manager.removeLocationListener(listener)
817 // [kotlin_LocationManager_removeLocationListener]
818 }
819 }
820 }
821
822 /**
823 * Main demonstration method
824 */
825 fun runExample() {
826 println("=== LocationManager Example ===")
827
828 demonstrateLocationManagerMethods()
829 demonstrateTransmitterStatus()
830
831 // Wait a bit for location to load
832 Thread.sleep(2000)
833
834 cleanup()
835 println("=== Example completed ===")
836 }
837}
838
839/**
840 * Function to run the example
841 */
842fun main() {
843 val example = LocationManagerExample()
844 example.runExample()
845}