简体   繁体   中英

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:

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 .

For example, consider location1 is Melbourne Central and location2 is Mantra on the Park - can I query locations within the rectangle?

在此处输入图片说明

GeoFirestore starts off by querying the documents based on a 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 .

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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