Center map on user location
All checks were successful
Build and deploy Flutter Web / build (push) Successful in 2m28s
All checks were successful
Build and deploy Flutter Web / build (push) Successful in 2m28s
This commit is contained in:
32
lib/location/current_location.dart
Normal file
32
lib/location/current_location.dart
Normal file
@@ -0,0 +1,32 @@
|
||||
import 'package:geolocator/geolocator.dart';
|
||||
import 'package:latlong2/latlong.dart';
|
||||
|
||||
class CurrentLocation {
|
||||
Future<LatLng?> resolve() async {
|
||||
final serviceEnabled = await Geolocator.isLocationServiceEnabled();
|
||||
if (!serviceEnabled) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final permission = await _resolvePermission();
|
||||
if (permission != LocationPermission.whileInUse &&
|
||||
permission != LocationPermission.always) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final position = await Geolocator.getCurrentPosition(
|
||||
locationSettings: const LocationSettings(accuracy: LocationAccuracy.high),
|
||||
);
|
||||
|
||||
return LatLng(position.latitude, position.longitude);
|
||||
}
|
||||
|
||||
Future<LocationPermission> _resolvePermission() async {
|
||||
final permission = await Geolocator.checkPermission();
|
||||
if (permission != LocationPermission.denied) {
|
||||
return permission;
|
||||
}
|
||||
|
||||
return Geolocator.requestPermission();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user