1import 'package:navigine_sdk/navigine_sdk.dart';
7class LocationManagerExample
implements LocationListener {
9 LocationManager? _locationManager;
10 Location? _currentLocation;
12 LocationManagerExample() {
19 void _initializeSdk() {
23 _sdk = NavigineSdk.getInstance();
28 _sdk?.setUserHash(
'USER-HASH-HERE');
33 _sdk?.setServer(
'https://custom.navigine.com');
38 _locationManager = _sdk?.getLocationManager();
41 if (_locationManager !=
null) {
42 print(
'LocationManager successfully initialized');
45 print(
'Error initializing SDK: $e');
52 void demonstrateLocationManagerMethods() {
53 if (_locationManager ==
null) {
54 print(
'LocationManager not initialized');
60 _locationManager!.addLocationListener(
this);
65 _locationManager!.setLocationId(12345);
70 int currentLocationId = _locationManager!.getLocationId();
71 print(
'Current location ID: $currentLocationId');
76 _locationManager!.setLocationUpdateInterval(600);
81 _locationManager!.commitChanges();
93 void demonstrateLocationUsage(Location location) {
96 int locationId = location.getId();
97 print(
'Location ID: $locationId');
102 int version = location.getVersion();
103 print(
'Location version: $version');
108 String? name = location.getName();
109 print(
'Location name: $name');
114 String? description = location.getDescript();
115 print(
'Location description: $description');
120 bool isModified = location.getModified();
121 print(
'Location modified: $isModified');
126 List<String> graphTags = location.getGraphTags();
127 print(
'Available graph tags: $graphTags');
132 if (graphTags.isNotEmpty) {
133 ElevationGraph? elevationGraph = location.getElevationGraph(graphTags.first);
134 if (elevationGraph !=
null) {
135 demonstrateElevationGraphUsage(elevationGraph);
142 List<Category> categories = location.getCategories();
143 print(
'Number of categories: ${categories.length}');
148 if (categories.isNotEmpty) {
149 Category? category = location.getCategoryById(categories.first.getId());
150 if (category !=
null) {
151 demonstrateCategoryUsage(category);
158 List<Sublocation> sublocations = location.getSublocations();
159 print(
'Number of sublocations: ${sublocations.length}');
164 if (sublocations.isNotEmpty) {
165 Sublocation? sublocation = location.getSublocationById(sublocations.first.getId());
166 if (sublocation !=
null) {
167 demonstrateSublocationUsage(sublocation);
176 void demonstrateCategoryUsage(Category category) {
179 int categoryId = category.getId();
180 print(
'Category ID: $categoryId');
185 String? categoryName = category.getName();
186 print(
'Category name: $categoryName');
191 String? imageUrl = category.getImageUrl();
192 if (imageUrl !=
null) {
193 print(
'Category image URL: $imageUrl');
201 void demonstrateSublocationUsage(Sublocation sublocation) {
204 int sublocationId = sublocation.getId();
205 print(
'Sublocation ID: $sublocationId');
210 String? sublocationName = sublocation.getName();
211 print(
'Sublocation name: $sublocationName');
216 String? sublocationDescription = sublocation.getDescript();
217 print(
'Sublocation description: $sublocationDescription');
222 int categoryId = sublocation.getCategoryId();
223 print(
'Sublocation category ID: $categoryId');
228 int locationId = sublocation.getLocation();
229 print(
'Sublocation location ID: $locationId');
234 double width = sublocation.getWidth();
235 print(
'Sublocation width: $width meters');
240 double height = sublocation.getHeight();
241 print(
'Sublocation height: $height meters');
246 double? altitude = sublocation.getAltitude();
247 if (altitude !=
null) {
248 print(
'Sublocation altitude: $altitude meters');
254 double azimuth = sublocation.getAzimuth();
255 print(
'Sublocation azimuth: $azimuth degrees');
260 GlobalPoint originPoint = sublocation.getOriginPoint();
261 print(
'Sublocation origin point: ${originPoint.getLat()}, ${originPoint.getLon()}');
266 String levelId = sublocation.getLevelId();
267 print(
'Sublocation level ID: $levelId');
272 String externalId = sublocation.getExternalId();
273 print(
'Sublocation external ID: $externalId');
278 List<ReferencePoint> referencePoints = sublocation.getReferencePoints();
279 print(
'Number of reference points: ${referencePoints.length}');
284 List<Venue> venues = sublocation.getVenues();
285 print(
'Number of venues: ${venues.length}');
290 List<Zone> zones = sublocation.getZones();
291 print(
'Number of zones: ${zones.length}');
296 List<Beacon> beacons = sublocation.getBeacons();
297 print(
'Number of beacons: ${beacons.length}');
302 List<Wifi> wifis = sublocation.getWifis();
303 print(
'Number of WiFi access points: ${wifis.length}');
308 List<Eddystone> eddystones = sublocation.getEddystones();
309 print(
'Number of Eddystone beacons: ${eddystones.length}');
314 Graph? graph = sublocation.getGraph();
316 demonstrateGraphUsage(graph);
322 Graph? graphByTag = sublocation.getGraph(
"main");
323 if (graphByTag !=
null) {
324 print(
'Found graph with tag "main"');
325 demonstrateGraphUsage(graphByTag);
331 if (venues.isNotEmpty) {
332 Venue? venueById = sublocation.getVenueById(venues.first.getId());
333 if (venueById !=
null) {
334 print(
'Found venue by ID: ${venueById.getId()}');
335 demonstrateVenueUsage(venueById);
342 if (zones.isNotEmpty) {
343 Zone? zoneById = sublocation.getZoneById(zones.first.getId());
344 if (zoneById !=
null) {
345 print(
'Found zone by ID: ${zoneById.getId()}');
346 demonstrateZoneUsage(zoneById);
353 GlobalPoint globalPoint = GlobalPoint(55.7558, 37.6176);
354 LocationPoint localPoint = sublocation.globalToLocal(globalPoint);
355 print(
'Global point ${globalPoint.getLat()}, ${globalPoint.getLon()} converted to local: ${localPoint.getX()}, ${localPoint.getY()}');
360 LocationPoint localPoint2 = LocationPoint(100.0, 200.0);
361 GlobalPoint globalPoint2 = sublocation.localToGlobal(localPoint2);
362 print(
'Local point ${localPoint2.getX()}, ${localPoint2.getY()} converted to global: ${globalPoint2.getLat()}, ${globalPoint2.getLon()}');
367 ImageWrapper? image = sublocation.getImage(1024);
369 print(
'Sublocation image obtained with max texture size 1024');
377 void demonstrateVenueUsage(Venue venue) {
380 int venueId = venue.getId();
381 print(
'Venue ID: $venueId');
386 int locationId = venue.getLocationId();
387 print(
'Venue location ID: $locationId');
392 int sublocationId = venue.getSublocationId();
393 print(
'Venue sublocation ID: $sublocationId');
398 String? venueName = venue.getName();
399 print(
'Venue name: $venueName');
404 String? phone = venue.getPhone();
405 print(
'Venue phone: $phone');
410 String? venueDescription = venue.getDescript();
411 print(
'Venue description: $venueDescription');
416 String? alias = venue.getAlias();
417 print(
'Venue alias: $alias');
422 int categoryId = venue.getCategoryId();
423 print(
'Venue category ID: $categoryId');
428 String? imageUrl = venue.getImageUrl();
429 if (imageUrl !=
null) {
430 print(
'Venue image URL: $imageUrl');
436 Point? point = venue.getPoint();
438 demonstratePointUsage(point);
446 void demonstrateZoneUsage(Zone zone) {
449 int zoneId = zone.getId();
450 print(
'Zone ID: $zoneId');
455 int locationId = zone.getLocationId();
456 print(
'Zone location ID: $locationId');
461 int sublocationId = zone.getSublocationId();
462 print(
'Zone sublocation ID: $sublocationId');
467 String? zoneName = zone.getName();
468 print(
'Zone name: $zoneName');
473 String? zoneDescription = zone.getDescript();
474 print(
'Zone description: $zoneDescription');
479 int categoryId = zone.getCategoryId();
480 print(
'Zone category ID: $categoryId');
485 String? alias = zone.getAlias();
486 print(
'Zone alias: $alias');
491 String? color = zone.getColor();
492 print(
'Zone color: $color');
497 List<Point> polygon = zone.getPolygon();
498 print(
'Zone polygon points: ${polygon.length}');
505 void demonstrateBeaconUsage(Beacon beacon) {
508 Point? point = beacon.getPoint();
510 demonstratePointUsage(point);
516 int locationId = beacon.getLocationId();
517 print(
'Beacon location ID: $locationId');
522 int sublocationId = beacon.getSublocationId();
523 print(
'Beacon sublocation ID: $sublocationId');
528 String? beaconName = beacon.getName();
529 print(
'Beacon name: $beaconName');
534 int major = beacon.getMajor();
535 print(
'Beacon major: $major');
540 int minor = beacon.getMinor();
541 print(
'Beacon minor: $minor');
546 String? uuid = beacon.getUuid();
547 print(
'Beacon UUID: $uuid');
552 int? power = beacon.getPower();
554 print(
'Beacon power: $power');
560 TransmitterStatus status = beacon.getStatus();
561 print(
'Beacon status: $status');
568 void demonstrateWifiUsage(Wifi wifi) {
571 Point? point = wifi.getPoint();
573 demonstratePointUsage(point);
579 int locationId = wifi.getLocationId();
580 print(
'WiFi location ID: $locationId');
585 int sublocationId = wifi.getSublocationId();
586 print(
'WiFi sublocation ID: $sublocationId');
591 String? wifiName = wifi.getName();
592 print(
'WiFi name: $wifiName');
597 String? mac = wifi.getMac();
598 print(
'WiFi MAC: $mac');
603 TransmitterStatus status = wifi.getStatus();
604 print(
'WiFi status: $status');
611 void demonstrateEddystoneUsage(Eddystone eddystone) {
614 Point? point = eddystone.getPoint();
616 demonstratePointUsage(point);
622 int locationId = eddystone.getLocationId();
623 print(
'Eddystone location ID: $locationId');
628 int sublocationId = eddystone.getSublocationId();
629 print(
'Eddystone sublocation ID: $sublocationId');
634 String? eddystoneName = eddystone.getName();
635 print(
'Eddystone name: $eddystoneName');
640 String? namespaceId = eddystone.getNamespaceId();
641 print(
'Eddystone namespace ID: $namespaceId');
646 String? instanceId = eddystone.getInstanceId();
647 print(
'Eddystone instance ID: $instanceId');
652 int? power = eddystone.getPower();
654 print(
'Eddystone power: $power');
660 TransmitterStatus status = eddystone.getStatus();
661 print(
'Eddystone status: $status');
668 void demonstratePointUsage(Point point) {
671 double x = point.getX();
672 print(
'Point X: $x');
677 double y = point.getY();
678 print(
'Point Y: $y');
685 void demonstrateGraphUsage(Graph graph) {
688 List<GraphVertex> vertices = graph.getVertices();
689 print(
'Number of graph vertices: ${vertices.length}');
694 List<GraphEdge> edges = graph.getEdges();
695 print(
'Number of graph edges: ${edges.length}');
702 void demonstrateGraphVertexUsage(GraphVertex vertex) {
705 int vertexId = vertex.getId();
706 print(
'Vertex ID: $vertexId');
711 Point? point = vertex.getPoint();
713 demonstratePointUsage(point);
719 String? name = vertex.getName();
720 print(
'Vertex name: $name');
725 bool isExternal = vertex.getIsExternal();
726 print(
'Vertex is external: $isExternal');
731 bool isElevation = vertex.getIsElevation();
732 print(
'Vertex is elevation: $isElevation');
739 void demonstrateGraphEdgeUsage(GraphEdge edge) {
742 double weight = edge.getWeight();
743 print(
'Edge weight: $weight');
748 int dst = edge.getDst();
749 print(
'Edge destination ID: $dst');
754 int src = edge.getSrc();
755 print(
'Edge source ID: $src');
760 int weightCoef = edge.getWeightCoef();
761 print(
'Edge weight coefficient: $weightCoef');
768 void demonstrateElevationGraphUsage(ElevationGraph elevationGraph) {
771 List<GraphEdge> edges = elevationGraph.getEdges();
772 print(
'Number of elevation graph edges: ${edges.length}');
775 for (
int i = 0; i < edges.length; i++) {
776 GraphEdge edge = edges[i];
777 print(
'Elevation graph edge ${i + 1}:');
778 demonstrateGraphEdgeUsage(edge);
786 void demonstrateTransmitterStatus() {
789 print(
'Available transmitter statuses:');
790 print(
' - TransmitterStatus.active: ${TransmitterStatus.active}');
791 print(
' - TransmitterStatus.inactive: ${TransmitterStatus.inactive}');
799 if (_locationManager !=
null) {
802 _locationManager!.removeLocationListener(
this);
810 Future<void> runExample() async {
811 print(
'=== LocationManager Example ===');
813 demonstrateLocationManagerMethods();
814 demonstrateTransmitterStatus();
817 await Future.delayed(Duration(seconds: 2));
820 print(
'=== Example completed ===');
826 void onLocationLoaded(Location? location) {
827 print(
'Location loaded successfully');
828 _currentLocation = location;
829 if (location !=
null) {
830 demonstrateLocationUsage(location);
837 void onLocationUploaded(
int locationId) {
838 print(
'Location uploaded: $locationId');
844 void onLocationFailed(
int locationId, Object error) {
845 print(
'Failed to load location $locationId: $error');
855 static Future<void> initializeInFlutter() async {
856 print(
'=== LocationManager Initialization in Flutter ===');
858 final example = LocationManagerExample();
859 await example.runExample();
861 print(
'Initialization completed');
869 final example = LocationManagerExample();
870 await example.runExample();