static startGeofenceService(
{required String? pointedLatitude,
required String? pointedLongitude,
required String? radiusMeter,
int? eventPeriodInSeconds}) {
//parsing the values to double if in any case they are coming in int etc
double latitude = _parser(pointedLatitude);
double longitude = _parser(pointedLongitude);
double radiusInMeter = _parser(radiusMeter);
//starting the geofence service only if the positionstream is null with us
if (_positionStream == null) {
_geoFencestream = _controller.stream;
_positionStream = Geolocator.getPositionStream(
desiredAccuracy //here the error: LocationAccuracy.high,
).listen((Position position) {
double distanceInMeters = Geolocator.distanceBetween(
latitude, longitude, position.latitude, position.longitude);
_printOnConsole(
latitude, longitude, position, distanceInMeters, radiusInMeter);
_checkGeofence(distanceInMeters, radiusInMeter);
_positionStream!
.pause(Future.delayed(Duration(seconds: eventPeriodInSeconds!)));
});
_controller.add(GeofenceStatus.init);
}
}
I have no idea why the ‘desiredAccuracy’ part gets error. I think the code is correct right? Please send me help how to figure out that issue
2
Answers
desiredAccuracy
is a parameter ofGeolocator.getCurrentPosition()
. You are usingGeolocator.getPositionStream()
. This method doesn’t have that parameter. I’d suggest looking at the package’s documentation to see how to use that method: https://pub.dev/packages/geolocatorTo make your code work,
Declare a variable
locationSettings
first like thisThen modify
getPositionStream
like in the snippet below