Is GPS activated - Flutter

前端 未结 3 917
执念已碎
执念已碎 2020-12-28 10:38

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.

3条回答
  •  执念已碎
    2020-12-28 11:11

    Update 2019/10/25

    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
    }
    

    Old answer (package outdated)

    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 
    }
    

提交回复
热议问题