Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failed to add geofence error #80

Open
hundredball opened this issue May 28, 2021 · 1 comment
Open

Failed to add geofence error #80

hundredball opened this issue May 28, 2021 · 1 comment

Comments

@hundredball
Copy link

I downloaded the FlutterGeofencing code and tried to utilize the geofencing plugin in my project.
I created a button for registering geofences. After creating the google map, I pressed the button and got the following error on the Android emulator.

I/flutter (28044): Permission status: PermissionStatus.granted
E/GeofencingPlugin(28044): Failed to add geofence: com.google.android.gms.common.api.ApiException: 1004:
E/flutter (28044): [ERROR:flutter/lib/ui/ui_dart_state.cc(199)] Unhandled Exception: PlatformException(com.google.android.gms.common.api.ApiException: 1004: , null, null, null)
E/flutter (28044): #0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:597:7)
E/flutter (28044): #1 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:177:18)
E/flutter (28044):
E/flutter (28044): #2 GeofencingManager.registerGeofence (package:geofencing/src/geofencing.dart:148:5)
E/flutter (28044):
E/flutter (28044): #3 _HomePageState._registerGeofences (package:google_maps_geojson/main.dart:398:9)
E/flutter (28044):
E/flutter (28044):

Since the error code means that the client doesn't have sufficient location permission to perform geofencing operations. I used the permission_handler plugin to assure that location permission is granted before initializing GeofencingManager. Permission is also granted before registering geofences.

Future initPlatformState() async {
_status = await Permission.location.request();
print('Location permission status: $_status');
print('Initializing...');
await GeofencingManager.initialize();
print('Initialization done');
}

However, I can successfully add the geofences without any issues when using the physical Android device. Is it possible that there's a conflict between google map and geofencing in the emulator but not in the physical devices?

Below is my flutter version. Any feedbacks are appreciated. Thank you for your time.
Screen Shot 2021-05-27 at 9 56 54 PM

@hundredball
Copy link
Author

hundredball commented May 28, 2021

I realized that I forgot to add background location permission in AndroidManifest.xml.

<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION"/>

After I added it and removed location_permission parts, now it works in both emulator and physical device!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant