-
Notifications
You must be signed in to change notification settings - Fork 3
/
geolocator.dart
38 lines (35 loc) · 1.51 KB
/
geolocator.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// Copyright (c) 2023, Halil Durmus. Please see the AUTHORS file for details.
// All rights reserved. Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
import 'package:windows_devices/windows_devices.dart';
import 'package:windows_system/windows_system.dart';
void main() async {
final status = await Geolocator.requestAccessAsync();
if (status == GeolocationAccessStatus.denied) {
print('Error: Location access denied.\n\n'
'Grant access from the Location settings by turning on the following '
'settings:\n'
' - Location services\n'
' - Let apps access your location\n'
' - Let desktop apps access your location\n\n'
'Then try this example again.');
// Launch the Location settings page
await Launcher.launchUriAsync(Uri.parse('ms-settings:privacy-location'));
return;
}
final locator = Geolocator()..allowFallbackToConsentlessPositions();
final location = await locator.getGeopositionAsync();
if (location?.coordinate case final coordinate?) {
final position = switch (coordinate.point?.position) {
BasicGeoposition(:final latitude, :final longitude) =>
'($latitude, $longitude)',
_ => 'N/A'
};
print('Current location: $position');
print('Location accuracy: ±${coordinate.accuracy} meters');
print('Current heading: ${coordinate.heading ?? 'N/A'}');
print('Position source: ${coordinate.positionSource.name}');
} else {
print('No location received.');
}
}