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);
}
}
我不知道为什么“desiredAccuracy”部分会出错。我认为代码是正确的,对吗?请给我发送帮助如何解决这个问题
2条答案
按热度按时间5f0d552i1#
desiredAccuracy
是Geolocator.getCurrentPosition()
的一个参数。你使用的是Geolocator.getPositionStream()
。这个方法没有那个参数。我建议你看看这个包的文档来了解如何使用这个方法:https://pub.dev/packages/geolocatorqcuzuvrc2#
要使代码正常工作,
首先声明变量
locationSettings
,如下所示然后修改
getPositionStream
,如下面的代码片段所示