GPS是否已激活-颤振
问题内容:
是否可以在Flutter中查明GPS是否已激活?我使用的是插件位置,但是在那里我只获得位置,而不是GPS的状态。
问题答案:
更新2019/10/25
位置包现在具有一个函数(serviceEnabled()
),用于检测位置服务是否已启用,并按照文档中的说明和示例所示返回布尔值:
bool serviceStatus = await _locationService.serviceEnabled();
if (service) {
// service enabled
} else {
// service not enabled, restricted or permission denied
}
旧答案(包已过时)
使用地理位置,您可以检查位置服务是否正常运行。它通常比位置包包含更多的可定制性。
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
}