flutterlocation
flutterlocation copied to clipboard
SERVICE_STATUS_ERROR while trying to activate geolocation
I'm trying to ask user to activate location with requestService() function on an Android device. However, an error is throw: SERVICE_STATUS_ERROR.
I've tried the exact same code on another android phone and it's working perfectly, I do have a pop up asking me if I'm agree to activate location.
The phone which the code not working is a Logicom Le Hola and the working one is a Samsung Galaxy S7 Edge.
I'm on location v4.1.1
Here is my flutter doctor -v: [√] Flutter (Channel stable, 2.0.1, on Microsoft Windows [version 10.0.18363.1379], locale fr-FR) • Flutter version 2.0.1 at C:\src\flutter • Framework revision c5a4b4029c (7 days ago), 2021-03-04 09:47:48 -0800 • Engine revision 40441def69 • Dart version 2.12.0
[√] Android toolchain - develop for Android devices (Android SDK version 29.0.2) • Android SDK at C:\Users\Pierrick\AppData\Local\Android\sdk • Platform android-30, build-tools 29.0.2 • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01) • All Android licenses accepted.
[√] Chrome - develop for the web • Chrome at C:\Program Files (x86)\Google\Chrome\Application\chrome.exe
[√] Android Studio (version 4.0) • Android Studio at C:\Program Files\Android\Android Studio • Flutter plugin version 47.1.2 • Dart plugin version 193.7361 • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)
[√] IntelliJ IDEA Community Edition (version 2019.1) • IntelliJ at C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2019.1.2 • Flutter plugin can be installed from: https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: https://plugins.jetbrains.com/plugin/6351-dart
[√] VS Code (version 1.52.0) • VS Code at C:\Users\Pierrick\AppData\Local\Programs\Microsoft VS Code • Flutter extension version 3.17.0
[√] Connected device (5 available) • Le Hola (mobile) • 1903910700015 • android-arm • Android 8.1.0 (API 27) • SM G531F (mobile) • 4b1346d2a7bec200 • android-arm • Android 5.1.1 (API 22) • SM G935F (mobile) • ce11160bbcca310e02 • android-arm64 • Android 8.0.0 (API 26) • Chrome (web) • chrome • web-javascript • Google Chrome 88.0.4324.190 • Edge (web) • edge • web-javascript • Microsoft Edge 89.0.774.48
• No issues found!
Here is my code:
loc.Location location = new loc.Location();//explicit reference to the Location class
bool _serviceEnabled;
PermissionStatus _permissionGranted;
LocationData _locationData;
String error;
try {
_serviceEnabled = await location.serviceEnabled();
if (!_serviceEnabled) {
_serviceEnabled = await location.requestService();
if (!_serviceEnabled) {
return false;
}
}
_permissionGranted = await location.hasPermission();
if (_permissionGranted == PermissionStatus.denied) {
_permissionGranted = await location.requestPermission();
if (_permissionGranted != PermissionStatus.granted) {
return false;
}
}
} on PlatformException catch (e) {
if (e.code == 'PERMISSION_DENIED') {
error = 'Permission denied';
} else if (e.code == 'PERMISSION_DENIED_NEVER_ASK') {
error = 'Permission denied - please ask the user to enable it from the app settings';
}
print(e.code);
location = null;
}
Thanks !
I have this problem as well. I can get my location once, but then it's all errors. I'm saving my location on shared prefs then I want the app to keep checking the location for comparison purposes.
Apparently being in airplane mode does not only disable network connection but also the ability to request GPS services. So you would need to check for airplane mode first before requesting GPS services in order to avoid this error.
That was it in my case, thanks !
Thanks for the report, the airplane mode seems to broke the detection on Android, not sure why.