I’ve been using the Geolocator package for a while and it works good, but for the last 2 days it’s not working.
Am trying to get last known position, and if there is none i try to get the current posiotion.
getLastKnownPosition() returns null, and the getCurrentPosition() never finishes and doesn’t return anything.
PS: On android emulator and IOS simulator it works fine, but in my android physical device it doesn’t work.
Here is my function:
Future<Position> locateUser() async {
final result = await Geolocator.getLastKnownPosition(
forceAndroidLocationManager: true);
if (result != null) {
return result;
}
final result1 = await Geolocator.getCurrentPosition();
return result1;
}
-I have tried uninstalling the app and re-install
-I have tried turning off and on GPS
2
Answers
Try these following points –
for e.g. –
final result1 = await Geolocator.getCurrentPosition().timeout( Duration(seconds: 10), onTimeout: () { ///you can throw TimeoutException("Location request timed out."); }, );
or you can retry by try and catch and also by 3 retries
like :- `
Make sure your app
has permission
to accessyour location
check here