imperiumlabs / GeoFirestore-Android

GeoFirestore for Android - Realtime location queries with Firestore
MIT License
123 stars 36 forks source link

Listeners Doesn't Seem To Work #9

Closed marijalukaroska1 closed 6 years ago

marijalukaroska1 commented 6 years ago
  GeoQuery geoQuery = FirestoreManager.getInstance().getGeoFirestoreUsers().queryAtLocation(new GeoPoint(latitude, longitude), 0.5);

        geoQuery.addGeoQueryDataEventListener(new GeoQueryDataEventListener() {
            @Override
            public void onDocumentEntered(DocumentSnapshot documentSnapshot, GeoPoint geoPoint) {
                Log.d(TAG, "marija document entered: " + documentSnapshot.toObject(UserModel.class));
                UserModel userModel = documentSnapshot.toObject(UserModel.class);
                if (!userModelListNearby.contains(userModel)) {
                    userModelListNearby.add(userModel);
                    nearbyRecyclerViewAdapter.notifyItemInserted(userModelListNearby.size());
                }
            }

            @Override
            public void onDocumentExited(DocumentSnapshot documentSnapshot) {
                Log.d(TAG, "marija document exited: " + documentSnapshot.toObject(UserModel.class));
                UserModel userModel = documentSnapshot.toObject(UserModel.class);
                int positionItemRemoved = userModelListNearby.indexOf(userModel);
                userModelListNearby.remove(userModel);
                nearbyRecyclerViewAdapter.notifyItemRemoved(positionItemRemoved);
            }

            @Override
            public void onDocumentMoved(DocumentSnapshot documentSnapshot, GeoPoint geoPoint) {
                Log.d(TAG, "marija document moved: " + documentSnapshot.toObject(UserModel.class));
            }

            @Override
            public void onDocumentChanged(DocumentSnapshot documentSnapshot, GeoPoint geoPoint) {
                Log.d(TAG, "marija document changed: " + documentSnapshot.toObject(UserModel.class));
                UserModel userModelChanged = documentSnapshot.toObject(UserModel.class);
                if (userModelChanged != null) {
                    for (Iterator<UserModel> iterator = userModelListNearby.iterator(); iterator.hasNext(); ) {
                        UserModel userModel = iterator.next();
                        if (userModel.getUid().equals(userModelChanged.getUid())) {
                            iterator.remove();
                        }
                    }
                    userModelListNearby.add(userModelChanged);
                    nearbyRecyclerViewAdapter.notifyDataSetChanged();
                }
            }

            @Override
            public void onGeoQueryReady() {
                Log.d(TAG, "onGeoQueryReady");
            }

            @Override
            public void onGeoQueryError(Exception e) {
                Log.d(TAG, "marija error: " + e.getMessage());
            }
        });

At first as I implemented this library the listener was working, but now I cant listen for changes. I was debugging and it seems that the listener is not attached at all. Can you tell me what is the problem?

marijalukaroska1 commented 6 years ago

I was storing the GeoPoint with error

geoFirestoreUsers.setLocation(uid, new GeoPoint(latitude, -longitude), new GeoFirestore.CompletionListener() { @Override public void onComplete(Exception e) { if(e!=null){ //TODO: handle exception return; } Log.d(TAG, "marija Location saved on server successfully!"); } });

Somehow I forgot to delete the - in the longitude.