transistorsoft / flutter_background_geolocation_firebase

Firebase proxy for Flutter Background Geolocation SDK
MIT License
21 stars 7 forks source link

addGeofences method not working #16

Open pablog9 opened 4 years ago

pablog9 commented 4 years ago

I have flutter_background_geolocation + background_geolocation_firebase correctly working (Android) with locations: My setup looks like this:

BackgroundGeolocationFirebase.configure(BackgroundGeolocationFirebaseConfig(
  locationsCollection: "/vehicles/${_vehicle.id}/locations",  
  geofencesCollection: "/routes/${_currentRoute.id}/geofences",  
  updateSingleDocument: false
));

Locations are working as expected creating a subcollection inside current vehicle document.

Now I am trying to add geofences, adding multiple geofences at once (2 for this example: id: 1, id: 21) to a list:

List<bg.Geofence> geofences = new List<bg.Geofence>();
// foreach step in steps
Bg.Geofence geofence = bg.Geofence(
    identifier: step.index.toString(),
    radius: 200,
    latitude: step.latitude,
    longitude: step.longitude,
    notifyOnEntry: false,
    notifyOnExit: false,
    notifyOnDwell: true,
    loiteringDelay: 30000,
    // 30 seconds
    extras: {"type": step.type});
geofences.add(geofence);
// end foreach
if (geofences.isNotEmpty)
  bg.BackgroundGeolocation.addGeofences(geofences);

But nothing happens, subcollection is never created and these logs are shown:

I/TSLocationManager( 5389): [c.t.l.data.sqlite.GeofenceDAO destroy]
I/TSLocationManager( 5389): ✅ 1
I/TSLocationManager( 5389): [c.t.l.data.sqlite.GeofenceDAO create]
I/TSLocationManager( 5389): ✅ 1
I/TSLocationManager( 5389): [c.t.l.data.sqlite.GeofenceDAO destroy]
I/TSLocationManager( 5389): ✅ 21
I/TSLocationManager( 5389): [c.t.l.data.sqlite.GeofenceDAO create]
I/TSLocationManager( 5389): ✅ 21
D/TSLocationManager( 5389): [c.t.l.g.TSGeofenceManager c] ℹ️ Persist monitored geofences: []

Why are there sqlite references if I am using the firebase version?

christocracy commented 4 years ago

But nothing happens, subcollection is never created and these logs are shown:

Those logs are normal.

Why are there sqlite references if I am using the firebase version?

Because the plugin stores ADDED geofences in its SQLite database. This is the collection of geofences you've asked the plugin to monitor.

I think you're confused about added geofences vs geofence events.

When a geofence EXIT / ENTER event occurs, then the plugin will post that event to Firebase.