I am trying to get the data from firestore using where query but on calling the get() and OnComplete() methods, my program's control won't go inside the oncomplete method.
When I return the HashMap it always returns null and even tried checking through log if control goes inside the OnComplete method but it doesn't.
Edit: The onFailure() method doesn't work either.
HashMap<String,String> doesMeetingPointExists(LatLng latLng)
{
String lat = String.valueOf(latLng.getLatitude());
String longi = String.valueOf(latLng.getLongitude());
final HashMap<String,String> jsonObject = new HashMap<>();
Query q = firebaseFirestore.collection("meeting_points").whereEqualTo("latitude",lat).whereEqualTo("longitude",longi);
q.get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
@Override
public void onComplete(@NonNull Task<QuerySnapshot> task) {
if (task.getResult().isEmpty()){
jsonObject.put("isNull", "true");
Log.d("TAG","DATA"+jsonObject.toString());
}
else{
Log.d("TAG", "IN ON Fail");
QuerySnapshot querySnapshot = task.getResult();
for (QueryDocumentSnapshot documentSnapshot: querySnapshot){
Map<String,Object> map = documentSnapshot.getData();
jsonObject.put("isNull","false");
jsonObject.put("LocationName", String.valueOf(map.get("place_name")));
jsonObject.put("LocationAddress", String.valueOf(map.get("place_address")));
Log.d("TAG","DATA"+jsonObject.toString());
}
}
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Log.d("TAG", "IN ON Fail");
jsonObject.put("isNull", "true");
Timber.e("Errora"+"---"+e.getMessage());
}
});
Log.d("TAG",jsonObject.toString());
return jsonObject;
}