Flutter Location packages does not return current location on iOS

1,278

I managed to solve it, if it happens to you check to do not call .getLocation() while a onChangedPosition listener is active.

Share:
1,278
Gabriel Costache
Author by

Gabriel Costache

Updated on December 22, 2022

Comments

  • Gabriel Costache
    Gabriel Costache over 1 year

    I'm stuck with this problem, If I try to call:

    Location location = Location();
    LocationData data = await location.getLocation();
    

    The future does never return anything, it just keeps going without returning values. This is kinda weird because in my application I also have google maps and they find without a problem my position, so it is not a GPS / Permission problem.

    On Android this problem does not exist, just on iOS (Targetting iOS 10.0 at the moment).

    Edit:

    After more tests I concluded that it actually works, but just the first time the app is opened, every other request to that method does not respond.

  • Gabriel Costache
    Gabriel Costache almost 4 years
    Yeah, I know, that's already done, sadly it doesn't work :)
  • Gabriel Costache
    Gabriel Costache almost 4 years
    Code is fine, those are the lines that give throuble, I tried to mock the location and the code keeps running properly as expected, when I try to use a real location (Or faked by the simulator, but still "real") it doesn't work 'cause .getLocation() does not return anything and onChangedLocation aswell. Permissions and service status are OK, I check and print them everytime I call getLocation()
  • Gabriel Costache
    Gabriel Costache almost 4 years
    @Palejandro , you can read more and fine some code i've wrote at this link: github.com/Lyokone/flutterlocation/issues/…
  • Admin
    Admin about 2 years
    Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.