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
CodePudding user response:
desiredAccuracy
is a parameter of Geolocator.getCurrentPosition()
. You are using Geolocator.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/geolocator
CodePudding user response:
To make your code work,
Declare a variable locationSettings
first like this
final LocationSettings locationSettings = LocationSettings(
accuracy: LocationAccuracy.high,
distanceFilter: 100,
double latitude = _parser(pointedLatitude);
double longitude = _parser(pointedLongitude);
double radiusInMeter = _parser(radiusMeter);
);
Then modify getPositionStream
like in the snippet below
_positionStream = Geolocator.getPositionStream(
locationSettings: locationSettings
).listen((Position position) {