简体   繁体   English

Flutter 位置包不返回 iOS 上的当前位置

[英]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.这有点奇怪,因为在我的应用程序中我也有谷歌地图,他们发现我的 position 没有问题,所以这不是 GPS / 权限问题。

On Android this problem does not exist, just on iOS (Targetting iOS 10.0 at the moment).在 Android 上不存在此问题,仅在 iOS 上(目前针对 iOS 10.0)。

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:要在 iOS 中使用它,您必须在 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.我设法解决了这个问题,如果您碰巧在 onChangedPosition 侦听器处于活动状态时检查不 call.getLocation()。

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]. Go 到顶部栏中的模拟器设置,单击“功能”==>“位置”从各个位置选择进行模拟:[无,自定义位置,城市跑步,城市自行车骑行,高速公路,苹果]。

Should work then provided Info.plist is properly set-up, and Android Manifest is correct.如果 Info.plist 设置正确,并且 Android 清单正确,那么应该可以工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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