Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"location.getLocation()" sometimes doesn't work #949

Open
burekas7 opened this issue Apr 24, 2024 · 5 comments
Open

"location.getLocation()" sometimes doesn't work #949

burekas7 opened this issue Apr 24, 2024 · 5 comments

Comments

@burekas7
Copy link

burekas7 commented Apr 24, 2024

Describe the bug
Sometimes when running this code:
await location.getLocation();
It doesn't continue to the next line and not even caught in a catch block
And I don't see anything in the logs.

UPDATE:
It seems that sometimes the process just takes him so long for some reason.
Why is that?

Versions:
5.0.3
6.0.1

Tested on:

  • Android
@amanSixDreams
Copy link

(Android) when i use location.changeSettings(accuracy: LocationAccuracy.low); then its not working.
I try lot but its not working.

Version
6.0.1

Future<(bool, LocationData?)> permissionWithLoction(bool initState) async {
Location location = Location();

bool serviceEnabled;
PermissionStatus permissionGranted;
LocationData? locationData;

try {
serviceEnabled = await location.serviceEnabled();
if (!serviceEnabled) {
serviceEnabled = await location.requestService();
if (!serviceEnabled) {
throw Exception();
}
}

permissionGranted = await location.hasPermission();
if (permissionGranted == PermissionStatus.denied) {
  permissionGranted = await location.requestPermission();
  if (permissionGranted.name.toString() != "granted" &&
      permissionGranted.name.toString() != "grantedLimited") {
    permissionGranted = PermissionStatus.denied;
    throw Exception();
  } else {
    await location.changeSettings(accuracy: LocationAccuracy.low);
    locationData = await location.getLocation();
    return (true, locationData);
  }
} else {
  location.changeSettings(accuracy: LocationAccuracy.low);
  locationData = await location.getLocation();

  return (true, locationData);
}

} catch (e) {
await openAppSettings(initState);
permissionGranted = PermissionStatus.denied;
// return (permissionGranted, locationData);
}
return (false, locationData);
}

@adiTzoref
Copy link

adiTzoref commented Aug 21, 2024

Update:
Now it doesn't work on iOS, I don't get any response and the async-await is stuck.
Any idea?
(iOS 17.5.1)

Version 6.0.2

@DennisNoens
Copy link

@adiTzoref is 'precise location' turned off? Because that's an issue I noticed as well.

I opened a PR for this.

@burekas7
Copy link
Author

@adiTzoref is 'precise location' turned off? Because that's an issue I noticed as well.

I opened a PR for this.

No.
Precise Location in settings is ON.
But I think that also when I set it OFF it was the same.

@nadavfima
Copy link

nadavfima commented Sep 6, 2024

Having similar issues, also with precise location ON.
Seems it's something with calling the function too early (cubit's constructor), vs app's lifecycle or widget's initState/dispose which seems to work better

Edit: Indeed it seems related to await location.changeSettings. awaiting the changeSettings breaks something.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants