如何使用 flutter_geofire 将实时位置发送到 Cloud Firestore?

问题描述

以前我可以在 realtime Database 上发送实时位置,现在我正在使用 cloud firestore 但不知道如何向它发送实时位置

方法成功创建了一个位置为 latitudelongitude数据库集合

 Future<DocumentReference> OnlineNow() async {
    Position position = await Geolocator.getCurrentPosition(
        desiredAccuracy: LocationAccuracy.high);

    GeoFirePoint point =
        geo.point(latitude: position.latitude,longitude: position.longitude);
    return peopleOnline
        .doc(currentFirebaseUser.uid)
        .collection("online")
        .add({'position': point.data});
  }

方法用于发送实时位置

 void getLocationLiveUpdates() {
    StreamSubscription<Position> hoMetabPageStreamSubscription;
    hoMetabPageStreamSubscription =
        Geolocator.getPositionStream().listen((Position position) {
      initPositionPoint = position;
      print("Position $initPosition");
    });

    
  }
}

我确实成功获得了实时位置,但我在 cloud firestore 中更新了吗?

在实时数据库中是这样的。

void getLocationLiveUpdates() {
  StreamSubscription<Position> hoMetabPageStreamSubscription;
  hoMetabPageStreamSubscription =
      Geolocator.getPositionStream().listen((Position position) {
    currentPosition = position;
    Geofire.setLocation(
        currentFirebaseUser.uid,position.latitude,position.longitude);
    LatLng latlng = LatLng(position.latitude,position.longitude);
    googlemapController.animateCamera(cameraupdate.newLatLng(latlng));
  });
}

解决方法

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

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

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