0

我有 2 个要连接在一起的应用程序,它们的工作方式如下:它类似于送餐,我有一个餐厅应用程序,它将添加餐厅位置,我将这个位置按纬度和经度存储在我的 Firebase 上餐厅的集合。在另一个应用程序“食客”应用程序上,我想显示 Firestore 中附近的餐厅文档(文档现在包括名称、图像和描述)。

使用“食客”应用程序,我已经可以存储他们当前的位置。我唯一想做的就是展示附近的餐馆。

这是我的 showNearbyCompanies() 函数

Stream showNearbyCompanies() async* {
    var pos = await location.getLocation();

    GeoFirePoint point =
        geo.point(latitude: pos.latitude, longitude: pos.longitude);

    double distance = 30;

    double lat = 0.023323826086956514;
    double lon = 0.02926080000000002776;

    double lowerLat = point.latitude - (lat * distance);
    double lowerLon = point.longitude - (lon * distance);

    double greaterLat = point.latitude + (lat * distance);
    double greaterLon = point.longitude + (lon * distance);

    GeoPoint lesserGeoPoint = GeoPoint(lowerLat, lowerLon);
    GeoPoint greaterGeoPoint = GeoPoint(greaterLat, greaterLon);

    Query query = _firebaseFirestore
        .collection("Companies")
        .where("location", isGreaterThan: lesserGeoPoint)
        .where("location", isLessThan: greaterGeoPoint);

    yield query;
  }

**//This is another example instead of query**


showNearbyCompanies() async {
    var pos = await location.getLocation();

    GeoFirePoint point =
        geo.point(latitude: pos.latitude, longitude: pos.longitude);

    double distance = 30;

    Stream<List<DocumentSnapshot>> stream = geo
        .collection(collectionRef: _firebaseFirestore.collection("Companies"))
        .within(center: point, radius: distance, field: 'location');

    stream.listen((List<DocumentSnapshot> documentList) {
      // print(stream.length);
      print('Here');
      print(documentList[0].data());
    });
  }

我需要在这里显示它,这是我想要做的,但显然不起作用,因为 Query 不是字符串,但这是我无法解决的问题:

代码

Container(
            child: StreamBuilder(
              stream: showNearbyCompanies(),
              builder: (context, snapshot) {
                if (!snapshot.hasData) {
                  return Text("Loading");
                }
                return Text(snapshot.data); // this needs to be the query, I don't know how to do
              },
            ),
          ),
4

0 回答 0