GPS是否已激活-颤振 [英] Is GPS activated - Flutter

查看:68
本文介绍了GPS是否已激活-颤振的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法可以在Flutter中查明GPS是否被激活?
我使用了插件位置,但是我只得到位置而不是状态

Is there a way to find out in Flutter if the GPS is activated or deactivated? I use the plugin location however there I get only the location and not the state of the GPS.

推荐答案

更新2019/10/25

位置包现在具有一个函数( serviceEnabled()),用于检测位置服务是否已启用并按照其文档,并显示在示例

The location package now has a function (serviceEnabled()) to detect whether the location service is enabled and returns a bool as described in its docs and shown in the example:

bool serviceStatus = await _locationService.serviceEnabled();
if (service) {
    // service enabled
} else {
    // service not enabled, restricted or permission denied
}

旧答案(软件包已过时)

使用地理位置,您可以检查定位服务是否在运行。

With geolocations you can check wether the location service is operational. It generally includes more customizability then the location package.

final GeolocationResult result = await Geolocation.isLocationOperational();
if(result.isSuccessful) { 
    // location service is enabled, and location permission is granted 
} else { 
    // location service is not enabled, restricted, or location permission is denied 
}

这篇关于GPS是否已激活-颤振的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆