toGpsPointAndReset method

void toGpsPointAndReset()

Creates and adds a point representing the current internal state to resultReporter, if the current state is sufficiently defined to represent such a point. The internal state is consequently reset, whether a point was created or not.

The returned point may be GpsPoint if no accuracy is present in the current state, or GpsMeasurement if the accuracy is present.

Implementation

void toGpsPointAndReset() {
  if (isUndefined) {
    reset();
    return;
  }

  var time =
      GpsTime.fromMillisecondsSinceEpochUtc(timestampMs!, autoClamp: true);

  if (_prevParsedPoint != null &&
      _minSecondsBetweenDatapoints != null &&
      time.difference(_prevParsedPoint!.time) <=
          _minSecondsBetweenDatapoints!) {
    // Don't do anything, we don't want this point.
  } else if (_accuracyThreshold != null &&
      _values[_indexAccuracy] != null &&
      _values[_indexAccuracy]! > _accuracyThreshold!) {
    // Don't do anything, we don't want this point.
  } else {
    // We do want this point -> create and report it.
    var p = GpsPoint(
        time: time,
        latitude: latitudeE7! / 1E7,
        longitude: longitudeE7! / 1E7,
        altitude: altitude?.toDouble());

    // If we have accuracy specified, return a GpsMeasurement object that's
    // capable of storing accuracy information.
    if (accuracy != null) {
      p = GpsMeasurement.fromPoint(p, accuracy: accuracy!.toDouble());
    }

    _prevParsedPoint = p;
    resultReporter(p);
  }

  reset();
}