栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

Geolocator插件获取当前位置

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Geolocator插件获取当前位置

问题是google_maps_flutter软件包需要访问您位置的权限,但该软件包没有本机代码来请求该权限。

因此,您需要编写本机代码或仅安装另一个能够获得该许可权的软件包。

安装此程序:https :
//pub.dartlang.org/packages/location

然后:

getLocationPermission() async {    final Location location = new Location();    try {      location.requestPermission(); //to lunch location permission popup    } on PlatformException catch (e) {      if (e.pre == 'PERMISSION_DENIED') {        print('Permission denied');      }    }  }

或者,如果您想要更坚实的代码,这是我用于某些项目的代码(带有位置包):

//Show some loading indicator depends on this boolean variablebool askingPermission = false;@override  void initState() {    this.getLocationPermission();    super.initState();  }  Future<bool> getLocationPermission() async {    setState(() {      this.askingPermission = true;    });    bool result;    final Location location = Location();    try {      if (await location.hasPermission())        result = true;      else {        result = await location.requestPermission();      }      print('getLocationPermission: '          '${result ? 'Access Allowed' : 'Access Denied'}');    } catch (log, trace) {      result = false;      print('getLocationPermission/log: $log');      print('getLocationPermission/trace: $trace');    } finally {      setState(() {        this.askingPermission = false;      });    }    return result;  }


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/376763.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号