Flutter 按纬度和经度从 Firebase 显示附近的用户

问题描述

我有 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
              },),

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)