|
|
|
|
@ -18,11 +18,12 @@ class LocationUtils {
|
|
|
|
|
AppSharedPreferences sharedPref = new AppSharedPreferences();
|
|
|
|
|
|
|
|
|
|
bool isShowConfirmDialog;
|
|
|
|
|
bool isShowLocationTimeoutDialog;
|
|
|
|
|
BuildContext context;
|
|
|
|
|
bool isHuawei;
|
|
|
|
|
final GeolocatorPlatform _geolocatorPlatform = GeolocatorPlatform.instance;
|
|
|
|
|
|
|
|
|
|
LocationUtils({required this.isShowConfirmDialog, required this.context, this.isHuawei = false});
|
|
|
|
|
LocationUtils({required this.isShowConfirmDialog, required this.context, this.isHuawei = false, this.isShowLocationTimeoutDialog = true});
|
|
|
|
|
|
|
|
|
|
void getCurrentLocation({Function(LatLng)? callBack}) async {
|
|
|
|
|
if (Platform.isAndroid && isHuawei) {
|
|
|
|
|
@ -32,12 +33,15 @@ class LocationUtils {
|
|
|
|
|
if (value) {
|
|
|
|
|
await Geolocator.checkPermission().then((permission) async {
|
|
|
|
|
if (permission == LocationPermission.always || permission == LocationPermission.whileInUse) {
|
|
|
|
|
Geolocator.getCurrentPosition(desiredAccuracy: LocationAccuracy.best, timeLimit: Duration(seconds: 5)).then((value) {
|
|
|
|
|
Geolocator.getCurrentPosition(desiredAccuracy: LocationAccuracy.medium, timeLimit: Duration(seconds: 5)).then((value) {
|
|
|
|
|
setLocation(value);
|
|
|
|
|
if (callBack != null) callBack(LatLng(value.latitude, value.longitude));
|
|
|
|
|
}).catchError((err) {
|
|
|
|
|
print(err);
|
|
|
|
|
if (isShowConfirmDialog) showLocationTimeOutDialog(failureCallBack: (){});
|
|
|
|
|
if (isShowConfirmDialog && isShowLocationTimeoutDialog)
|
|
|
|
|
showLocationTimeOutDialog(failureCallBack: () {
|
|
|
|
|
Geolocator.openAppSettings();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -130,7 +134,9 @@ class LocationUtils {
|
|
|
|
|
accuracy: 1.0,
|
|
|
|
|
heading: 0.0,
|
|
|
|
|
speed: 0.0,
|
|
|
|
|
speedAccuracy: 1, altitudeAccuracy: 0.0, headingAccuracy: 0.0,
|
|
|
|
|
speedAccuracy: 1,
|
|
|
|
|
altitudeAccuracy: 0.0,
|
|
|
|
|
headingAccuracy: 0.0,
|
|
|
|
|
// altitudeAccuracy: 0.0,
|
|
|
|
|
// headingAccuracy: 0.0,
|
|
|
|
|
// altitudeAccuracy: 0,
|
|
|
|
|
|