【问题标题】:Can I query a Firestore database by GeoPoint values to find local places?我可以通过 GeoPoint 值查询 Firestore 数据库以查找本地位置吗?
【发布时间】:2021-04-07 01:27:45
【问题描述】:

我想知道这是否可能,因为我已经搜索了很长时间,但没有找到任何文档表明可以从 Java 中的 Android 对 Firestore 中存储的 GeoPoints 进行查询?

【问题讨论】:

标签: java android firebase google-cloud-firestore geopoints


【解决方案1】:

我可以通过 GeoPoint 值查询 Firestore 数据库以查找本地地点吗?

当然可以。如果您想通过特定的 GeoPoint 对象查询 Firestore,那么您应该perform a Query。假设您在数据库中有一个文档,该文档具有 GeoPoint 类型的属性,例如,51.5074 表示纬度,0.1278 表示经度,则需要以下查询:

FirebaseFirestore rootRef = FirebaseFirestore.getInstance();
CollectionReference placesRef = rootRef.collection("places");
Query geoQuery = placesRef.whereEqualTo("geoPoint", new GeoPoint(51.5074, 0.1278));
geoQuery.get().addOnCompleteListener(/* ... */);

但是,如果您想查询附近的位置,请注意 Firebase 最近推出了Geo queries,这意味着您可以获取会落入特定半径范围内的文档。

【讨论】:

  • 感谢亚历克斯 - 正是我所追求的!我已经设法存储了一些 GeoHashes 并很容易地按位置查询它们。 This YouTube video 由 Google 工程师提供,从 22:00 开始对了解 GeoHashes 也很有帮助。
  • @thomas_roe 不客气,Thomas。我知道那个视频,是的,它真的很有帮助。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2023-03-30
  • 2018-03-22
  • 1970-01-01
  • 2021-03-30
  • 1970-01-01
  • 1970-01-01
  • 2019-06-18
相关资源
最近更新 更多