Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/powerbi/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
List 颤振-显示列表距离时设置最大半径_List_Dart_Flutter_Location_Distance - Fatal编程技术网

List 颤振-显示列表距离时设置最大半径

List 颤振-显示列表距离时设置最大半径,list,dart,flutter,location,distance,List,Dart,Flutter,Location,Distance,我正在开发最近的食物盘应用位置。我使用这个插件根据离用户最近的位置来显示它 我想知道如何设置最大半径?例如小于30公里 这是我的代码: _foodByCategories.sort((a, b) { var distance1 = new GreatCircleDistance.fromDegrees( latitude1: model.userLocation == null ? 0.0 : model.userLocation["

我正在开发最近的食物盘应用位置。我使用这个插件根据离用户最近的位置来显示它

我想知道如何设置最大半径?例如小于30公里

这是我的代码:

 _foodByCategories.sort((a, b) {
      var distance1 = new GreatCircleDistance.fromDegrees(
          latitude1:
              model.userLocation == null ? 0.0 : model.userLocation["latitude"],
          longitude1: model.userLocation == null
              ? 0.0
              : model.userLocation["longitude"],
          latitude2: a.lat,
          longitude2: a.long);
      double totaldistance1 = distance1.haversineDistance();

      var distance2 = new GreatCircleDistance.fromDegrees(
          latitude1:
              model.userLocation == null ? 0.0 : model.userLocation["latitude"],
          longitude1: model.userLocation == null
              ? 0.0
              : model.userLocation["longitude"],
          latitude2: b.lat,
          longitude2: b.long);
      double totaldistance2 = distance2.haversineDistance();
      return (totaldistance1 - totaldistance2).toInt();
    });

任何答案都将不胜感激。

在您使用的软件包中,我看不到任何方法可以做到这一点。您可以建议开发人员在中添加此功能


或者,您可以在代码中获得
总距离
,这样您就可以执行一个简单的
if语句
,检查总距离是否大于设置的最大半径。

如果我理解您的问题正确的话

_foodByCategories.where((a) {
  var distance = new GreatCircleDistance.fromDegrees(latitude1: double.parse(widget.lat), longitude1: double.parse(widget.lng), latitude2: double.parse(a.lat), longitude2: double.parse(a.lng));
  var totaldistance = distance.haversineDistance().toStringAsFixed(2);
  double distanceDouble1 = double.parse(totaldistance);
  return distance <= 30000; // or something like that
}).sort ... // and your sorting code
\u食品分类。其中((a){
var distance=新的大循环距离.fromDegrees(纬度1:double.parse(widget.lat),经度1:double.parse(widget.lng),纬度2:double.parse(a.lat),经度2:double.parse(a.lng));
var totaldistance=distance.HaversinedDistance().toStringAsFixed(2);
double distance double1=double.parse(总距离);

返回距离不幸的是,开发人员不再开发此插件。我已经同意,但是
totalDistance1-TotalDistance2<30
的结果是,它返回一个布尔值。你的意思是你需要它返回一个布尔值吗?我需要返回Int。。(排序请参见
totaldistance 1-totaldistance 2
之后的内容,然后我将其转换为.Int()
)排序前使用
\u foodByCategories.where()
。将距离计算移到外部的单独函数。
\u foodByCategories.where(/*计算距离并按距离过滤<30*/)。排序(/*计算距离并按距离排序_diff*/);
您保存了我的生日兄弟(y)