简体   繁体   English

查询 2 个 GeoPoints 之间的位置

[英]Query locations between 2 GeoPoints

With GeoFirestore I can query a location (lat/lon) to see if any locations in my collection/database are within a certain radius:使用GeoFirestore,我可以查询位置(纬度/经度)以查看我的集合/数据库中是否有任何位置在某个半径范围内:

val collectionRef = FirebaseFirestore.getInstance().collection("locations")
val geoFirestore = GeoFirestore(collectionRef)

val location1 = GeoPoint(37.7832, -122.4056)
val location2 = GeoPoint(37.3832, -121.4056)
val geoQuery = geoFirestore.queryAtLocation(location1, 0.6)

However, I want to query for a 3rd location between location1 and location2 .但是,我想查询location1location2之间的第三个location2

For example, consider location1 is Melbourne Central and location2 is Mantra on the Park - can I query locations within the rectangle?例如,考虑location1是 Melbourne Central, location2是 Mantra on the Park - 我可以查询矩形内的位置吗?

在此处输入图片说明

GeoFirestore starts off by querying the documents based on a GeoHash. GeoFirestore 通过基于 GeoHash 查询文档开始。 This leads to a roughly rectangular shape, which GeoFirestore then in-memory reduces to the requested range by checking the actual distance of each document from the center .这导致大致为矩形的形状,GeoFirestore 然后在内存中通过检查每个文档与 center 的实际距离将其缩小到请求的范围。

While returning all documents in the rectangular shape isn't supported by the GeoFirestore out of the box, it should be fairly easy to modify the library to not do the distance filtering.虽然 GeoFirestore 不支持立即返回矩形中的所有文档,但修改库以不进行距离过滤应该相当容易。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM