【问题标题】:Sort list items based on gps distance根据 GPS 距离对列表项进行排序
【发布时间】:2021-05-14 23:47:59
【问题描述】:

您好,下面的 dart 代码包含一系列带有 gps 位置的位置,在启动应用程序时,我必须检索我保存在两个变量中的 long 和 lat,接下来我要做的是排序位置列表基于从哪里找到我的 gps 距离这是基于 lat 和 long 我该怎么办?

飞镖代码:

double longitudine=0,latitudine=0;

Future<bool> caricamentoSedi() async {
    await _getGpsValue();
    listaSedi = await Sede.caricamento();
    //This point write function order listaSedi
    return true;
  }

Sede 类:

class Sede {
  //Costruttore di una sede
  Sede(this.info_id, this.app_id, this.info_title, this.descrizione, this.email,
      this.telefono, this.lat, this.long, this.note,this.rgbcolor);

  final int info_id, app_id;
  double lat = 0, long = 0;
  final String info_title, descrizione, email, telefono, note,rgbcolor;

  //Descrizione: Funzione che effettua il caricamento delle sedi
  static Future<List<Sede>> caricamento() async {
    return await SedeController.caricamento();
  }

  //Descrizione: funzione che recupero l'email
  String getEmail() {
    return email;
  }

  //Descrizione: funzione che recupera la descrizione
  String getDescrizione() {
    return descrizione;
  }

  //Descrizione: funzione che recupera il numero di telefono rimuovendo li spazi vuoti presenti nel valore
  String getTelefono() {
    return telefono.replaceAll(new RegExp(r"\s+"), "");
  }

  //Recupero latitudine
  double getLatitudine() {
    return lat;
  }

  //Recupero longitudine
  double getLongitudine() {
    return long;
  }

  //Recupero note
  String getNote() {
    return this.note;
  }

 
}

【问题讨论】:

  • 不,问题是如何通过计算从我到 sede 的距离来排序列表元素

标签: flutter dart gps


【解决方案1】:

您可以实现自己的方法来计算 2 点之间的距离,然后使用它对列表进行排序: https://stackoverflow.com/a/64966888/14394936

或者你可以使用像 geolocator 这样的库: https://stackoverflow.com/a/64890616/14394936

对列表进行排序: https://stackoverflow.com/a/12889025/14394936

https://api.dart.dev/stable/2.10.5/dart-core/List/sort.html

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-02-21
    • 1970-01-01
    • 1970-01-01
    • 2015-07-21
    • 2021-10-25
    • 2021-01-23
    • 1970-01-01
    相关资源
    最近更新 更多