【发布时间】:2019-12-27 03:35:48
【问题描述】:
我正在尝试通过获取当前用户位置来加载谷歌地图。
当我第一次注册 (firebase) 时,它会要求位置许可,那么只会出现这个异常。 (登录时没有这个,第一次注册后)
这是我在 pubspec.yaml 中的地理定位器和位置插件
geolocator: ^4.0.2 version
location: ^2.0.0
我该如何解决这个问题?
【问题讨论】:
我正在尝试通过获取当前用户位置来加载谷歌地图。
当我第一次注册 (firebase) 时,它会要求位置许可,那么只会出现这个异常。 (登录时没有这个,第一次注册后)
这是我在 pubspec.yaml 中的地理定位器和位置插件
geolocator: ^4.0.2 version
location: ^2.0.0
我该如何解决这个问题?
【问题讨论】:
正如官方示例所说,您应该先检查权限。像这样
Widget build(BuildContext context) {
return FutureBuilder<GeolocationStatus>(
future: Geolocator().checkGeolocationPermissionStatus(),
builder:
(BuildContext context, AsyncSnapshot<GeolocationStatus> snapshot) {
if (!snapshot.hasData) {
return const Center(child: CircularProgressIndicator());
}
if (snapshot.data == GeolocationStatus.denied) {
return const PlaceholderWidget('Access to location denied',
'Allow access to the location services for this App using the device settings.');
}
return Center(.... your code)
你可以在这里找到完整的例子https://github.com/Baseflow/flutter-geolocator/tree/develop/example
【讨论】: