moved method

GeofenceDatum? moved(
  1. GeoPosition location
)

Implementation

GeofenceDatum? moved(GeoPosition location) {
  GeofenceDatum? datum;
  if (center.distanceTo(location) < radius) {
    // we're inside the geofence
    switch (state) {
      case GeofenceState.unknown:
      case GeofenceState.outside:
        // if we came from outside the fence, we have now entered
        state = GeofenceState.inside;
        lastEvent = DateTime.now();
        datum = GeofenceDatum(type: GeofenceType.ENTER, name: name);
        break;
      case GeofenceState.inside:
        // if we were already inside, check if dwelling takes place
        if (lastEvent.add(dwell).isBefore(DateTime.now())) {
          // we have been dwelling in this geofence
          state = GeofenceState.inside;
          lastEvent = DateTime.now();
          datum = GeofenceDatum(type: GeofenceType.DWELL, name: name);
        }
        break;
    }
  } else {
    // we're outside the geofence - check if we have left
    if (state != GeofenceState.outside) {
      // we have just left the geofence
      state = GeofenceState.outside;
      lastEvent = DateTime.now();
      datum = GeofenceDatum(type: GeofenceType.EXIT, name: name);
    }
  }

  return datum;
}