As shown in the picture I have campaign branch which is a dynamic list where I save every campaigns data.
https://drive.google.com/file/d/16xe1aeAxEbtfiiUFoXtlqvFPucHejQp7/view?usp=sharing
Every campaign data includes location which is an other branch inside the campaign, I want to get location data of all campaigns. I tried it using the code below but it return null value.
void getCampaignsLocations(final OnGetDataListener onGetDataListener){
onGetDataListener.onStart();
Toast.makeText(this, "started", Toast.LENGTH_SHORT).show();
DatabaseReference campaignsRoot = FirebaseDatabase.getInstance().getReference();
DatabaseReference campaignsPath = campaignsRoot.child("campaigns");
ValueEventListener valueEventListener = new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
for(DataSnapshot ds: dataSnapshot.getChildren()){
LatLng l = ds.child("location").getValue(LatLng.class);
campaignsLocations.add(l);
onGetDataListener.onSuccess(dataSnapshot,0,"");
}
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
};
campaignsPath.addListenerForSingleValueEvent(valueEventListener);
}