addGpsLocation method

void addGpsLocation({
  1. TrackingMode? mode = TrackingMode.PLANAR,
})

Implementation

void addGpsLocation({TrackingMode? mode = TrackingMode.PLANAR}) async {
  Position position = await Geolocator.getCurrentPosition(
      desiredAccuracy: LocationAccuracy.high);
  var _location = new LatLng(position.latitude, position.longitude);
  if (isEditMode == true) {
    ///Find center position between two coordinate
    if (_tempLocation.length > 0) {
      if (_tempLocation.length > 1 && pointDistance) {
        ///Remove previous distance first point to last point
        await removeMarker(_endLoc);

        ///Create distance marker for first point to last point
        await createEndLoc(_tempLocation[0], _location);
      }

      if (pointDistance) {
        ///Create distance marker for last positions
        await createDistanceMarker(_tempLocation.last, _location);
      }
    }

    ///Adding new locations
    _tempLocation.add(_location);
    if (_uniqueID == "") {
      _uniqueID = Random().nextInt(10000).toString();
    }

    ///Create marker point
    Uint8List? markerIcon = await getUint8List(markerKey);
    setMarkerLocation(_tempLocation.length.toString(), _location, markerIcon);

    ///Set current tracking mode
    ///so we can use this variable in every function
    setTrackingMode(mode);
    if (trackingMode == TrackingMode.PLANAR) {
      setTempToPolygon();
    } else {
      setTempToPolyline();
    }
  }
  notifyListeners();
}