1

I'm wondering if this is possible, as I've searched for quite a while and not found any documentation that shows that a query can be made against stored GeoPoints in Firestore from Android in Java?

a_local_nobody
  • 7,947
  • 5
  • 29
  • 51
thomas_roe
  • 17
  • 1
  • 4

1 Answers1

1

Can I query a Firestore database by GeoPoint values to find local places?

Sure you can. If you want to query Firestore by a specific GeoPoint object, then you should perform a Query. Assuming that you have in the database a document that has a property of type GeoPoint which holds, for example, 51.5074 for latitude and 0.1278 for longitude, then the following query is required:

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

However, if you want to query nearby locations, please note that Firebase recently launched Geo queries, meaning that you can get documents that would fall into a specific radius.

Alex Mamo
  • 130,605
  • 17
  • 163
  • 193
  • 1
    Thanks Alex - exactly what I'm after! I've managed to store some GeoHashes and query them by location very easily. [This YouTube video](https://youtu.be/mx1mMdHBi5Q?t=1320) by a Google engineer, starting at 22:00 was also helpful to learn about GeoHashes. – thomas_roe Dec 31 '20 at 08:22
  • @thomas_roe You're very welcome, Thomas. I know that video, yes, it's really helpful. – Alex Mamo Dec 31 '20 at 17:19