简体   繁体   中英

Flutter Location packages does not return current location on iOS

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.

To use it in iOS, you have to add this permission in Info.plist:

NSLocationWhenInUseUsageDescription
NSLocationAlwaysUsageDescription


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

I was struggling with this for a while. Go to your simulator settings at the top bar, click the 'Features' ==> 'Location' pick from various locations to mock: [None, Custom Location, City Run, City Bicycle Ride, Freeway Drive, Apple].

Should work then provided Info.plist is properly set-up, and Android Manifest is correct.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM