I'm using Geolocator.getCurrentPosition() method:
Future<Position> getCurrentPosition({
LocationSettings? locationSettings,
LocationAccuracy desiredAccuracy = LocationAccuracy.best,
bool forceAndroidLocationManager = false,
Duration? timeLimit,
}) async {
LocationSettings? settings;
if (locationSettings != null) {
settings = locationSettings;
} else if (defaultTargetPlatform == TargetPlatform.android) {
settings = AndroidSettings(
accuracy: desiredAccuracy,
forceLocationManager: forceAndroidLocationManager,
);
}
try {
settings ??= LocationSettings(
accuracy: desiredAccuracy,
timeLimit: timeLimit,
);
debugPrint("await starts");
Position position = await Geolocator.getCurrentPosition(
locationSettings: settings,
).then(
(value) {
debugPrint("await stop");
return value;
},
);
return position;
} catch (e) {
debugPrint(e.toString());
return Geolocator.getCurrentPosition(
locationSettings: settings,
);
}
}
I tried to use other packages as well like Location but still not able to get location when internet is not available.