dart 未定义命名参数“desiredAccuracy”

pexxcrt2  于 2022-12-30  发布在  其他
关注(0)|答案(2)|浏览(163)
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”部分会出错。我认为代码是正确的,对吗?请给我发送帮助如何解决这个问题

5f0d552i

5f0d552i1#

desiredAccuracyGeolocator.getCurrentPosition()的一个参数。你使用的是Geolocator.getPositionStream()。这个方法没有那个参数。我建议你看看这个包的文档来了解如何使用这个方法:https://pub.dev/packages/geolocator

qcuzuvrc

qcuzuvrc2#

要使代码正常工作,
首先声明变量locationSettings,如下所示

final LocationSettings locationSettings = LocationSettings(
  accuracy: LocationAccuracy.high,
  distanceFilter: 100,
double latitude = _parser(pointedLatitude);
double longitude = _parser(pointedLongitude);
double radiusInMeter = _parser(radiusMeter);
);

然后修改getPositionStream,如下面的代码片段所示

_positionStream = Geolocator.getPositionStream(
       locationSettings: locationSettings
      ).listen((Position position) {

相关问题