flutterlocation icon indicating copy to clipboard operation
flutterlocation copied to clipboard

How to check Location Service Status?

Open naumanahmed19 opened this issue 8 years ago • 7 comments

hasPermission only checking if permission is guaranteed. Is there any way to check location service / GPS status if it activated/disabled?

naumanahmed19 avatar Nov 19 '18 11:11 naumanahmed19

I would like to know as well, this is not stable my app don't know what to do and just keeps waiting for a location

basestring2 avatar Mar 10 '19 09:03 basestring2

Got a work around, not sure if it the best way because I'm very new to flutter but not new to programming. I changed the getLocation to this

Future<LocationData> getLocation() => _channel
      .invokeMethod('getLocation')
      .then((result) => LocationData.fromMap(result.cast<String, double>()))
      .timeout(Duration(seconds: 1));

now I can Catch a timeout error like this

try {
      currentLocation = await  location.getLocation();
    } on PlatformException {
      currentLocation = null;
    } catch (e) {
      // can't get location, could be disabled!!!!
      currentLocation = null;
      print(e);
    } 

basestring2 avatar Mar 10 '19 10:03 basestring2

I'll look into adding this feature :)

Lyokone avatar Mar 16 '19 16:03 Lyokone

Hey ! In 2.2 I've added serviceEnabled() and requestService() in order to check and request Location Service status. Let me know if it correspond to what you need :)

Lyokone avatar Mar 19 '19 19:03 Lyokone

@Lyokone the method serviceEnabled() is not working on Android Pie. Do you know why?

vitaomds avatar Mar 29 '19 01:03 vitaomds

Hey ! It seems to be working fine on my end ( I'm using a Pie device to test the example app). Let me check again today.

Lyokone avatar Mar 29 '19 07:03 Lyokone

How to subscribe to serviceEnabled state changing?

mikeevstropov avatar May 15 '19 13:05 mikeevstropov