Search code examples
androidgoogle-cloud-firestoregeofirestore

How to Retrieve FireStore Users Within a Range With GeoFireStore Android


I am currently working on a program which requires containing location of users with Android Studio. In my users collection, I have location informations as geopoints for each user documents. I need to get all users which are in radius range of a circle. I found GeoFireStore of imperiumlabs -https://github.com/imperiumlabs/GeoFirestore-Android- for this geographic location processes. I can set and get location of a document(single user). But I want to define a center and check if there is/are anyone within the range.

As I understand I need to use geo query event listener as follows;

geoQuery.addGeoQueryEventListener(new GeoQueryEventListener() {...}

It has Key Entered, Key Moved, Query Ready, Query Error methods, but I couldn't manage what and how to use. I need returned informations of documents(users) which(who) are in my defined range. This way, I can show them main user.

For short words; can someone help me about understanding event listeners of geofirestore?

Thanks for your precious time.


Solution

  • After spending more and more hours I finally solved my issue with

    public void onDocumentEntered(DocumentSnapshot documentSnapshot, GeoPoint location) {}

    in the GeoQueryDataEventListener Interface. This method works recursively until meeting the requirements of query and I put it in onCreate. I just listed document_id's with documentSnapshot.getId() and tranferred them to an arraylist with mList.add(documentSnapshot.getId()) . Hope this can help someone take care.