Flutter Firestore get Array from Geopoint >> Instance of 'GeoPoint' <<

I've been getting this error ("Instance of 'GeoPoint) that I want to get the array list of the Geopoint from Firestore, I still don't know how to solve this, any help will be appreciated.

Image from Firestore (Array List GeoPoint)

This is my Class Model to get all of the document from Firestore

class ModelLA{

  String nama, kode, alamat, creator, pass, foto;
  List<GeoPoint> titikLokasi;

  ModelLA.fromMap(Map<String, dynamic> data){
    nama = data['nama'];
    kode = data['kode'];
    alamat = data['alamat'];
    creator = data['creator'];
    pass = data['pass'];
    foto = data['foto '];
    titikLokasi = List.from(data['titikLokasi']);
  }

}

This is how do I get all of the data

 Firestore.instance.collection('LA').getDocuments().then((value){
      value.documents.forEach((element) {
        if (value.documents.isNotEmpty){
          value.documents.forEach((element) async {
            ModelLA modelLA = ModelLA.fromMap(element.data);
          });
        }
      });

Return error:

[Instance of 'GeoPoint', Instance of 'GeoPoint', Instance of 'GeoPoint', Instance of 'GeoPoint', Instance of 'GeoPoint', Instance of 'GeoPoint']

Upvotes: 1

Views: 1712

Answers (1)

I already find the solution to retrieve all of the data from GeoPoint list, thank you for everyone who helps me, this is how do i get the data:

Firestore.instance.collection('LA').getDocuments().then((value){
      value.documents.forEach((element) {
        if (value.documents.isNotEmpty){
          value.documents.forEach((element) async {
            ModelLA modelLA = ModelLA .fromMap(element.data);
            print('Data: ${modelLA.titikLokasi.map((e) =>
            print('lat: ${e.latitude} + long: ${e.longitude}'))}');
          });
        }
      });
    });

Case closed

Upvotes: 1

Related Questions