【问题标题】:How to show Firebase firestore colletions of nearby collections by location inside a radius of the device using Flutter [duplicate]如何使用 Flutter 按设备半径内的位置显示附近集合的 Firebase Firestore 集合
【发布时间】:2021-07-11 00:24:47
【问题描述】:

我正在使用 Flutter 开发一个应用程序,例如送餐应用程序。所以我有餐厅应用程序和最终用户应用程序。

我现在在做什么

获取公司地址 (geoLocation),并使用带有 geohash 的 lat 和 lng 将位置存储在餐厅的 Firestore 集合中。对于最终用户应用,我正在获取当前设备位置。

我正在努力实现的目标

在最终用户应用上,我想创建一个列表,例如 uber Eats,使用最终用户设备的当前位置以及 Firestore 上的餐厅位置来显示附近的餐厅。

我正在使用 GeoFlutterFire 依赖项来获取位置。

我的功能

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

    GeoFirePoint point =
        geo.point(latitude: pos.latitude, longitude: pos.longitude);
    final CollectionReference users =
        _firebaseFirestore.collection("Companies");

    double radius = 10;
    String field = 'location';

    Stream<List<DocumentSnapshot>> stream = geo
        .collection(collectionRef: users)
        .within(center: point, radius: radius, field: field, strictMode: true);

    yield stream;
  }

我要在哪里显示列表

Container(
            child: StreamBuilder(
              stream: nearbyComp(),
              builder: (context, snapshot) {
                if (!snapshot.hasData) {
                  return Text("Loading");
                }
                return Container(
                  child: Text("companyName"), // This needs to be changed to a list? Display company name, image, etc, here.
                );
              },
            ),
          ),

当前问题

问题是,我找不到在最终用户屏幕上显示餐厅资料的方法,例如图像、名称等。我想我需要一个 ListView.Builder,但不知道该怎么做它与 nearComp() 函数上的 Stream 一起使用。

我的 Firestore

【问题讨论】:

    标签: firebase flutter google-maps google-cloud-firestore geolocation


    【解决方案1】:

    在您的流构建器的回报中:

    return ListView(children: [
    for (var item in snapshot.data) 
      ListTile( title: Text ( item["companyEmail"])) 
    // Or use item.data()["companyEmail"], I didn't work with //geoFire, but these should work since it's firebase.
    ])
    

    【讨论】:

    • type '_AsBroadcastStream>' 不是 'Iterable' 类型的子类型它返回这个:/并且 item.data() 也不起作用
    • 嘿,您对可能出现的问题有任何想法吗?
    猜你喜欢
    • 2021-08-06
    • 2020-12-28
    • 1970-01-01
    • 2011-12-28
    • 2021-11-25
    • 1970-01-01
    • 2020-10-10
    相关资源
    最近更新 更多