-1

Hello the dart code below contains a series of locations with the gps position, at the time of starting the app I have to retrieve the long and lat that I have saved in two variables, what I have to do next is to sort the list of locations based on the gps distance from where to find me this is based on lat and long how can I do?

Dart Code:

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:

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;
  }

 
}
riki
  • 1,502
  • 5
  • 17
  • 45

1 Answers1

0

You can implement your own method to calculate distance between 2 points, then use it to sort the list : https://stackoverflow.com/a/64966888/14394936

Or you can use a lib like geolocator : https://stackoverflow.com/a/64890616/14394936

Sort the list : https://stackoverflow.com/a/12889025/14394936

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

BabC
  • 1,044
  • 5
  • 18