flutterlocation
flutterlocation copied to clipboard
[iOS] "getLocation" not resolving
Describe the bug
a show a waiter around the function getLocation()
. so a customer found out, the waiter is not hiding. the reason is, that the line await _locationPlugin.getLocation()
is not resolving.
after testing and debugging i found out, that the function ist not resolving, if the user clicked "Allow once". i can reproduce it with an simulator, if i clicking "Allow once".
Expected behavior
getLocation
should be resolving or thrown a error.
Tested on:
- customer iOS device
- iOS iPad Air 2
- iOS Si
Additional logs in Visual Studio Code or in XCode i saw no errors.
EDIT
Flutter 2.2.3
location: ^4.3.0
EDIT
the devices , where we tested this behavior are real devices, but on simulator i get this issue too.
Same issue, its stuck...when i restart app it resolve it and continue...every second run of app works!!!
Same Issue, happens only on IOS
Same Issue, happens only on IOS
I'm also experiencing the exact same thing, function not resolving on the first run. We need to restart the app to go through getLocation()
Was anyone able to solve this ? I am currently facing the same issue. Android works fine its just IOS, even if I restart the app on the simulator it still doesn't ask for permissions. Are there any workarounds for this bug ?
I have the same issue.
However, I tried creating a simple example for demonstration and could not replicate this. So perhaps we're doing something wrong?
This is the dummy example I have created: location.zip
Correction: I can replicate it when giving the simulator a single custom location which doesn't change.
In this case, the first call to getLocation()
returns, however another call does not return and gets stuck.
If you set the simulator's location to "City Run" however, this is not reproducable. So it seems that this only happens when the location is fixed and unchanging.
Was anyone able to solve this ? I am currently facing the same issue. Android works fine its just IOS, even if I restart the app on the simulator it still doesn't ask for permissions. Are there any workarounds for this bug ?
the only workaround what i know do, is to timeout the promise, so that the App not freeze and waits for getLocation().
@Lyokone Could you review the merge request soon please? This is a huge issue for our app. Thanks!
I experienced this only on iOS simulator. Hope the merge request is reviewed soon.
Maybe requesting the location a second time is valid workaround for this. The first, the Future
of getLocation()
does not return, but the second time it does.
So instead of
LocationData location = await _locator.getLocation();
use this:
LocationData? location;
while(location == null) {
try {
location = await Future.any<LocationData>([
_locator.getLocation(), // we hope this returns first
Future.delayed(const Duration(seconds: 5), () => throw LocatorTimeout()),
]);
} on LocatorTimeout {
print('LocatorTimeout. Trying again...');
}
}
Does this work for you?
@Lyokone Could you review the merge request soon please? This is a huge issue for our app. Thanks!
I tested out that commit on my app but the issue still persists.
see implementation below
git:
url: https://github.com/ademanuele/flutterlocation.git
path: packages/location
ref: 6810b7e338173ff26a0a52a25721060a563e625f ```
Hi @wiseminds.
Do you mean you tried the code in this MR and it did not work for you? Could you describe any change in the behaviour if you notice any please?
There was no difference. I still couldn’t get location.
Maybe requesting the location a second time is valid workaround for this. The first, the
Future
ofgetLocation()
does not return, but the second time it does.So instead of
LocationData location = await _locator.getLocation();
use this:
LocationData? location; while(location == null) { try { location = await Future.any<LocationData>([ _locator.getLocation(), // we hope this returns first Future.delayed(const Duration(seconds: 5), () => throw LocatorTimeout()), ]); } on LocatorTimeout { print('LocatorTimeout. Trying again...'); } }
Does this work for you?
Actually the problem is that it doesn't work after first call. So it doesn't matter how many times you try...
@AlpSha Yes, I think you are right. The problem seems to different on different platforms. I had this problem on bith Android and iOS. On Android, the second call is successful so my workwaround fixes the issue on Android. But on iOS it looks like this is not the case. Did you test on Android or iOS?
@LostInDarkMath Tested on both. Android works fine without any workaround but iOS has the issue.
Hi,
I had the same issue on iOS Simulator. I've just noticed that the issue only occured when the simulator location settings (Features, Location) were set to Custom Location.... Any other setting it seemed to work fine. Might help?
Hi, i have the same issue, do you have any idea how can i fix-it please ?
Same issue any update ?
return await _location.getLocation().timeout(Duration(seconds: 5));
Now in Android the issue is pressent.
The problem persists for iOS.
this week icg noticed that getLocation still doesn't work in the iOS simulator.
the app keeps waiting for a result to come back or at least an error to be thrown.