【问题标题】:Flutter - How to save Firestore Geopoint to Json (especially Algolia)Flutter - 如何将 Firestore Geopoint 保存到 Json(尤其是 Algolia)
【发布时间】:2022-11-22 10:17:54
【问题描述】:

我在将 Firestore Geopoint 保存到 Json 文件时遇到问题。在我的 flutter 应用程序中,我这样保存 Geopoint。

 FirebaseFirestore.instance.collection('ZayyanProperties').get().then(
              (value) => value.docs.forEach(
                (element) {
                  var docRef = FirebaseFirestore.instance
                      .collection('ZayyanProperties')
                      .doc(element.id);

                  docRef.update({
                    'b18-geopoint': GeoPoint(16.00001, 96.00001)
                  }); 

Geopoint 的值正确存储在 Firestore 数据库中。请看我的 Firestore 数据库的截图here

我的问题是,当 Geopoint 作为 Json 保存到 Algolia 时,它没有正确保存。在Algolia的Json文件中,Firestore Geopoint保存为

  "_geoloc": {
    "lat": 16.00001,
    "lng": 96.00001
  },

但是,我认为它应该像这样保存??

  "b18-geopoint": {
    "lat": 16.00001,
    "lng": 96.00001
  },

请查看 Algolia Json here 的截图

所以,我的问题是如何在 Json 中正确保存 Geopoint?

先感谢您。 最好的

【问题讨论】:

  • 如果你想让 algolia 识别你的 lat/lng,那么你必须遵循 algolia 的要求。 algolia 需要 "_geoloc" 而不是“b18-geopoint”。

标签: json flutter google-cloud-firestore algolia


【解决方案1】:

为了让 Algolia 获取地理位置数据,您的记录应将地理位置信息保存到名为 _geoloc 的属性中。该属性可以是一个对象(具有latlng 属性),也可以是具有latlng 属性的对象列表。例如:

单条记录:

{
  "_geoloc": {
    "lat": 40.639751,
    "lng": -73.778925
  },
  ...
}

多记录:

{
  "_geoloc": [
    { "lat": 47.279430, "lng": 5.106450 },
    { "lat": 47.293228, "lng": 5.004570 },
    { "lat": 47.316669, "lng": 5.016670 } 
  ],
  ...
}

您可以找到有关地理定位和 Algolia here in the documentation 的更多信息。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-09-22
    • 2021-08-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-30
    相关资源
    最近更新 更多