Flutter-geolocator: Android Pie (API 28) Geolocator().getCurrentPosition() 不返回

创建于 2018-11-02  ·  39评论  ·  资料来源: Baseflow/flutter-geolocator

🐛 错误报告

当我使用 Android Pie (API 28) 调用在 Android 模拟器上运行 Geolocator().getCurrentPosition() 时根本没有返回。

我在 API 27 位置运行相同的代码返回正常。 我试图创建新的模拟器,没有任何变化。

配置

带 Android Pie 的 Android 模拟器(API 28)

版本: 2.1.0

平台:

  • [ ] :iphone: iOS
  • [X]:机器人:安卓
android

最有用的评论

我有同样的问题,我设置了超时功能。 当超时发生时,我调用 getLastKnownPosition()

Geolocator().getCurrentPosition().timeout(Duration(seconds: 10)).then((position) {
      //getting position without problems
      print(position);
    }).catchError((error) {
      if (error is TimeoutException) {
        Geolocator().getLastKnownPosition().then((position) {
          //getting last known position
          print(position);
        }).catchError((error) {
          //handle the exception
        });
      } else {
        //handle the exception
      }
    });

你也可以对流做同样的事情

所有39条评论

我也是,怎么了? :(

同样在这里!

@savjolovs如果我进行调试,调试器会在 Geolocator().getCurrentPosition() 上停止。 方法之后的断点没有被击中。 你能证实这种行为吗?

这里的行为相同,直到使用扩展控件推送一些坐标。
与两个物理设备之一的行为相同。 首先使用 android 5 - 工作正常,另一个使用 6 - 在 fakegps 位置启用之前没有响应。

+1 在这里

任何人的想法是什么原因? 此功能破坏了一切,有人尝试过其他插件吗?

检查显而易见的问题,对于那些有问题的人,您是否有 GPS 信号来获取位置并移动? 只是想知道它是否在更新之前坐在那里等待某个新位置?

@ibrierley似乎无论是否移动都无法获得 GPS 信号,但同时不同的应用程序(如谷歌地图)在定位当前位置时没有问题。 lastKnownPosition 返回大约几百米远的位置。 使用 android 5 根本没有问题,甚至没有要求位置许可(但不确定,可能是我在调试时错过了这个)

除了您关闭并再次打开应用程序之外,Android oreo 上的问题也相同

我一直在摆弄 Android Wear 手表,并且 GPS 有很多问题,但我似乎大部分时间都在工作(很长时间后它可能会超时,但我认为这是一个不同的问题)。

我不确定到底是什么让它起作用了,因为我已经尝试了很多东西,但也许有人可以检查这些,看看它们是否有帮助。

0) 确保您的设备可以接收 GPS 信号,因此在外部或通过模拟器向其提供位置(我向它提供了我下载的 GPX 路线以进行测试)。

1) 确保屏幕开启。 如果 GPS 处于最小模式,无论它叫什么,它可能会停止返回结果。 我在需要时使用 Screen 包和 Screen.keepOn(true) 强制打开屏幕; 如果屏幕关闭,它似乎会保留并缓冲一组位置,直到屏幕重新打开。

2)这些是我在AndroidManifest.xml中的权限,也许值得一试

``




请特别注意最后一个,因为我认为在一个版本的过程中发生了变化,这似乎有所帮助。 由于电池原因,您可能不想要唤醒锁定,但尝试这样做以消除问题所在可能很有用。

3) 我对 Stream 超时感到奇怪,所以我最终使用 geolocator.getPositionStream 启动了流,但实际上并没有使用它。 随着流的运行,我根据计时器调用 getCurrentPosition( desiredAccuracy: LocationAccuracy.high )。 我认为现在不需要这样做,因为我认为我最初的问题是屏幕关闭,但出于兴趣可能值得尝试。

如果有人尝试了上述方法但无法使其正常工作,您能否创建一个最小的 Flutter 应用程序,仅包含位置信息,我会看看它是否与我的一样失败。 开始的过程比它应该的要痛苦得多:/。

感谢@ibrierley提供信息,我会尽快尝试并报告我解决问题的经验。

今天使用其他工具进行了一些研究,例如在物理设备上进行 GPS 测试。
因此,当 GPS 测试无法使用卫星时(0 连接 1 可用,因为周围有云和大建筑物),即使谷歌地图或其他地图服务都有效,也没有响应。
当 sat 在线时没有响应,但在位置选项中定义了距离,但在这种情况下不是 100% - 需要某种 gps 漂移才能获得初始坐标。
我用 lastknownlocation 做了一些技巧来定位在那里,以在实际位置数据可用之前启动需要当前位置的应用程序。
可能会是一个很好的解决方案,有某种标志,如 isReady,在 Geolocator 中可能有回调,表明 GPS 服务已准备好通过流提供位置数据。

有没有人尝试过例如这个: https://github.com/Lyokone/flutterlocation ,或者这个: https://github.com/Lyokone/flutterlocation ? 所以我们可以排除与这个包无关的错误。

我试过了,最后得到了这个(这并不是说它不是
不过值得一试!)。 他们都有“一些”问题,我认为真的
因为 Android 有一些不明显的东西。

通常我发现当一个位置没有在任何
包),这是因为非抖动问题(例如 gps 已经进入
睡眠模式,或没有 GPS 信号)。

2018 年 11 月 15 日星期四晚上 7:26 HerrNiklasRaab [email protected]
写道:

有没有人试过这样的:
https://github.com/Lyokone/flutterlocation ,或者这个:
https://github.com/Lyokone/flutterlocation ? 所以我们可以排除错误
与此包无关。


你收到这个是因为你被提到了。
直接回复本邮件,在GitHub上查看
https://github.com/BaseflowIT/flutter-geolocator/issues/135#issuecomment-439160446
或静音线程
https://github.com/notifications/unsubscribe-auth/ADuG9WRbZuJYvi5N_2xrrku-Jurk6trIks5uvb_SgaJpZM4YKDSm
.

有人试试我的吗?
flutter_background_geolocation

出于兴趣关闭屏幕是否有效?

2018 年 11 月 15 日星期四晚上 8 点 16 分,Chris Scott通知@github.com
写道:

有人试试我的吗?
flutter_background_geolocation
https://pub.dartlang.org/packages/flutter_background_geolocation#-readme-tab-


你收到这个是因为你被提到了。
直接回复本邮件,在GitHub上查看
https://github.com/BaseflowIT/flutter-geolocator/issues/135#issuecomment-439175841
或静音线程
https://github.com/notifications/unsubscribe-auth/ADuG9f5uvZK0lDnYecMoFZhJnF0ylz6Pks5uvcuygaJpZM4YKDSm
.

即使您终止应用程序 ( stopOnTerminate: false ) 或重新启动设备 ( startOnBoot: true ),它也能工作。

我面临着同样的问题,它永远不会从getCurrentPosition
我有以下代码:
position = await Geolocator() .getCurrentPosition(desiredAccuracy: LocationAccuracy.best); setState(() { _position = position; }); if (position == null) Fluttertoast.showToast( msg: 'Position is null', toastLength: Toast.LENGTH_SHORT); else Fluttertoast.showToast( msg: 'Got Position', toastLength: Toast.LENGTH_SHORT);

权限是:
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> <uses-permission android:name="android.hardware.location.gps" /> <uses-permission android:name="android.hardware.location.network" /> <uses-permission android:name="android.permission.WAKE_LOCK" />
当我运行该程序时,位置指示器出现在屏幕顶部并保持不动,直到我关闭该程序。
请问有什么帮助吗?

同样的情况,getCurrentPosition 在使用 API 23 时不起作用。
任何解决此问题的方法或任何用于获取当前位置的替代软件包?

这有点棘手。 我现在可以通过首先启动谷歌地图应用程序让它工作,让它在点击我的位置时请求启用 GPS 的许可。 在那之后 getCurrentPosition 突然像魅力一样工作。

就我而言,我无法使用任何 API 检索位置,不确定这是否可以解决您的问题,但是
我尝试在这里删除 NOT 运算符,添加return语句并且它起作用了。 https://github.com/BaseflowIT/flutter-geolocator/blob/master/android/src/main/java/com/baseflow/flutter/plugin/geolocator/tasks/LocationUpdatesUsingLocationManagerTask.java#L52

// If we are listening to multiple location updates we can go ahead
// and report back the last known location (if we have one).
if(mStopAfterFirstLocationUpdate && mBestLocation != null) {
reportLocationUpdate(mBestLocation);
return;
}

我只是偶然发现了这个,因为在我使用另一个让我在生产中失望的插件后,我需要得到一个非常快速的修复。 我可以确认我已经在 API 23(物理设备)、API 24(物理设备)和 API 28(物理设备)上测试过它并且没有问题。 在 API 23 上,有人问我是否想帮助 Google 改进位置等,我只是说是的,它在大约 20 秒左右后加载了位置。 过去,我在让模拟器返回位置(原生 Android 开发)方面遇到了真正的问题,所以这可能只是模拟器问题吗?

我有同样的问题,我设置了超时功能。 当超时发生时,我调用 getLastKnownPosition()

Geolocator().getCurrentPosition().timeout(Duration(seconds: 10)).then((position) {
      //getting position without problems
      print(position);
    }).catchError((error) {
      if (error is TimeoutException) {
        Geolocator().getLastKnownPosition().then((position) {
          //getting last known position
          print(position);
        }).catchError((error) {
          //handle the exception
        });
      } else {
        //handle the exception
      }
    });

你也可以对流做同样的事情

@NMateu感谢您的贡献。 那很有帮助!

我在模拟器上遇到了同样的问题,但.forceAndroidLocationManager = true;为我修复了它。 似乎融合的位置管理器有时会妨碍。

有什么消息吗?

有没有人设法解决这个问题? 我真的需要完成这件事,伙计们!

同样的问题,它在 ios 设备上运行良好,但现在无法在 android 上获取位置。

是的,我实际上可以通过放置placemarkFromAddress方法获取地址。 但位置本身已损坏。

同样的问题在这里

void _getUserLocation() 异步 {
Geolocator geolocator = Geolocator()..forceAndroidLocationManager = true;
GeolocationStatus geolocationStatus = await geolocator.checkGeolocationPermissionStatus();
位置 position = await Geolocator()
.getCurrentPosition(desiredAccuracy: LocationAccuracy.high);
列表地标 = 等待地理定位器()
.placemarkFromCoordinates(position.latitude, position.longitude);
打印(” - - - - - - - - -”);
打印(地标[0]。位置);
打印(地理定位器.toString());
打印(地理定位状态。toString());
设置状态((){
_initialPosition = LatLng(position.latitude, position.longitude);

  locationController.text = placemark[0].name;
});

}

它显示错误的位置。

I/flutter (7363):纬度:37.421999899999996,经度:-122.08405750000001
I/flutter(7363):“地理定位器”的实例
I/flutter(7363):GeolocationStatus.granted

void _getUserLocation() 异步 {
Geolocator geolocator = Geolocator()..forceAndroidLocationManager = true;
GeolocationStatus geolocationStatus = await geolocator.checkGeolocationPermissionStatus();
位置 position = await Geolocator()
.getCurrentPosition(desiredAccuracy: LocationAccuracy.high);
列出地标 = await Geolocator()
.placemarkFromCoordinates(position.latitude, position.longitude);
打印(” - - - - - - - - -”);
打印(地标[0]。位置);
打印(地理定位器.toString());
打印(地理定位状态。toString());
设置状态((){
_initialPosition = LatLng(position.latitude, position.longitude);

  locationController.text = placemark[0].name;
});

}

使用此代码段在模拟器上工作
Geolocator()..forceAndroidLocationManager = true;

这个包对一切都很有吸引力

(https://github.com/alfanhui/new_geolocation)

我在少数 android 设备上遇到了同样的问题。 但我已经找到了解决办法——

您需要做的就是设置 Geolocator()..forceAndroidLocationManager = true 的值。

final Geolocator geolocator = Geolocator()..forceAndroidLocationManager = true;

6.0.0版本解决

Position position = await Geolocator.getCurrentPosition(
requiredAccuracy: LocationAccuracy.low,forceAndroidLocationManager: true);
它解决了我的问题

我在 forceAndroidLocationManager 行中收到一个错误,它显示红线,错误是.....“setter 'forceAndroidLocationManager' 没有为类型 'Geolocator' 定义。
尝试导入定义“forceAndroidLocationManager”的库,将名称更正为现有设置器的名称,或定义一个名为“forceAndroidLocationManager”的设置器或字段。”.........请有人帮我解决这个问题

@aditikumar-png 您使用的是哪个版本的地理定位器? 您最近可能更新到了 6.x 版。 这个版本有一个突破性的变化。 我们将Geolocator().forceAndroidLocationManager属性移动到getCurrentPositiongetPositionStream方法上的命名参数。

这意味着您现在可以像这样使用地理定位器:

final position = await Geolocator.getCurrentPosition(forceAndroidLocationManager: true);

而不是旧的:

final geolocator = Geolocator();
geolocator.forceAndroidLocationManager = true;

final position = await geolocator.getCurrentPosition();

@aditikumar-png 您使用的是哪个版本的地理定位器? 您最近可能更新到了 6.x 版。 这个版本有一个突破性的变化。 我们将Geolocator().forceAndroidLocationManager属性移动到getCurrentPositiongetPositionStream方法上的命名参数。

这意味着您现在可以像这样使用地理定位器:

final position = await Geolocator.getCurrentPosition(forceAndroidLocationManager: true);

而不是旧的:

final geolocator = Geolocator();
geolocator.forceAndroidLocationManager = true;

final position = await geolocator.getCurrentPosition();

非常感谢!!!!! 你在几秒钟内解决了我的问题,我从 9 小时开始就一直在努力解决这个问题

此页面是否有帮助?
0 / 5 - 0 等级

相关问题

prasant10050 picture prasant10050  ·  6评论

hectorAguero picture hectorAguero  ·  5评论

fawadkhanucp picture fawadkhanucp  ·  3评论

deisold picture deisold  ·  3评论

jaumard picture jaumard  ·  3评论