This is my data structure: 
Here I want to get the Latitude and longitude of the last element Location of the child based on id = "sd" .
Here is the code:
Query query = mDatabase.child("Users").orderByChild("Id").equalTo(busId); // busId = "sd" query.addListenerForSingleValueEvent(new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot) { for(DataSnapshot user : dataSnapshot.getChildren()) { Query lastItem = user.getRef().child("Location").orderByKey().limitToLast(1); lastItem.addListenerForSingleValueEvent(new ValueEventListener() { @Override public void onDataChange(DataSnapshot dataSnapshot) { String lat = dataSnapshot.child("Latitude").getValue().toString(); } @Override public void onCancelled(DatabaseError databaseError) { } }); break; } }
How can i do this? Thanks
source share