krish cyber
krish cyber

Reputation: 47

Want to get specific document fields from multiple documents in flutter cloud firestore

this image have the Database

I wanted to grab the latitude and longitude of all documents and display it in flutter map (leaflet).

FlutterMap(
      options: MapOptions(
        center: latLng.LatLng(51.5, -0.09),
        zoom: 13.0,
      ),
      layers: [
        TileLayerOptions(
            urlTemplate: "https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",
            subdomains: ['a', 'b', 'c']),
        MarkerLayerOptions(
          markers: [
            Marker(
              width: 80.0,
              height: 80.0,
              point: latLng.LatLng(51.5, -0.09),
              builder: (ctx) => Container(
                child: Icon(
                  Icons.circle,
                  size: 30,
                  color: dc,
                ),
              ),
            ),
          ],
        ),
      ],
    );

I put line 15 just for sample, i wanted to access all the user's lat long . please help, and thanks in advance

Upvotes: 0

Views: 519

Answers (1)

Huthaifa Muayyad
Huthaifa Muayyad

Reputation: 12373

  • First, you have to get the documents for your shopkeepers.
  • Then, iterate over those documents, and extract your lat and lng values, and add them to a list.

Future<List<LatLng>> getCordsFromFirebase() async {
List<LatLng> coordinatesList=[];
var results = await FirebaseFirestore.instance.collection('shopkeepers').get();

for (DocumentSnapshot item in results.docs){
coordinatesList.add(LatLng(item.data()['latitidue'], item.data()['longitude]));
 }
print('Length of cords list is: ' + coordinatesList.length.toString());//
return coordinatesList;
}

Upvotes: 0

Related Questions