颤动-在显示列表距离时设置最大半径 [英] flutter - Set the max radius when displaying the List distance

查看:56
本文介绍了颤动-在显示列表距离时设置最大半径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发最近的食品菜肴申请地点.我使用此插件 great_circle_distance,根据最接近用户的位置显示了该信息

I am developing the nearest Food Dish application location. I managed to display it based on the location closest to the user, using this plugin great_circle_distance

我想知道如何设置最大半径?前任. < 30公里

I want to know how to set the max radius? ex. < 30 Km

这是我的代码:

 _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 I understand your question correct

_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

这篇关于颤动-在显示列表距离时设置最大半径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆