Firebase 子侦听器未显示任何数据

Firebase child listener not showing any data

{
  "57c80ec0-e73f-49df-8296-25999e194288" : {
    "email" : "ss@zz.mm",
    "hotel" : {
      "-KEaYE1YfvPTRfgcO6Z_" : {
        "latit" : 20.15135303358223,
        "longit" : 23.86566750705242,
        "name" : "new marker"
      },
      "-KEaYGDhbFAN99GyY0cH" : {
        "latit" : 30.211601559876424,
        "longit" : -4.754576571285725,
        "name" : "new marker"
      },
      "-KEbjCjmx4-Xmr_1aVCy" : {
        "latit" : 20.58906906737089,
        "longit" : 25.271570831537247,
        "name" : "new marker"
      }
    },
    "password" : "nn",
    "username" : "ss"
  },
  "c01528ea-a22c-43de-b77a-bc833c5e394c" : {
    "email" : "ses@ses.ses",
    "hotel" : {
      "-KEaLImMODDRiDwK3gSo" : {
        "latit" : 18.160196227874213,
        "longit" : 26.094263345003128,
        "name" : "new marker"
      },
      "-KEaLKSEg1psa4xvggse" : {
        "latit" : 31.71881281252363,
        "longit" : -2.9933271557092667,
        "name" : "new marker"
      }
    },
    "password" : "ses",
    "username" : "ses"
  }
}

所以,我的想法是显示数据库中每个用户的所有酒店的标记,这里我遇到了查询问题。我不确定如何查询每个用户。

这是我尝试过的方法,但是当我调试时,hotel.getName 为空,纬度和经度为 0..

如果有人能告诉我我做错了什么或如何解决它,我将不胜感激..

这是我的第一个问题,如果我做错了什么,我深表歉意。 :)

干杯!

private Firebase firebase = new Firebase("https://josip-my-application.firebaseio.com/Users/");

@Override
public void requestMarkers() {

Firebase hotelsRef = new Firebase("https://josip-my-application.firebaseio.com/Users/");
    com.firebase.client.Query queryRef = hotelsRef.orderByChild("hotel");
    queryRef.addChildEventListener(new ChildEventListener() {
        @Override
        public void onChildAdded(DataSnapshot dataSnapshot, String s) {
            Hotel hotel = dataSnapshot.getValue(Hotel.class);
            presenter.onMarkersLoaded(hotel.getName(), hotel.getLatit(), hotel.getLongit());

        }

        @Override
        public void onChildChanged(DataSnapshot dataSnapshot, String s) {

        }

        @Override
        public void onChildRemoved(DataSnapshot dataSnapshot) {

        }

        @Override
        public void onChildMoved(DataSnapshot dataSnapshot, String s) {

        }

        @Override
        public void onCancelled(FirebaseError firebaseError) {

        }
    });

在您正在侦听的 /Users 节点下,您有用户节点。 Hotel 节点更深一层。

显示每个用户的酒店列表:

Firebase hotelsRef = new Firebase("https://josip-my-application.firebaseio.com/Users/");
com.firebase.client.Query queryRef = hotelsRef.orderByChild("hotel");
queryRef.addChildEventListener(new ChildEventListener() {
    @Override
    public void onChildAdded(DataSnapshot userSnapshot, String s) {
        DataSnapshot hotelsSnapshot = userSnapshot.child("hotel");
        for (DataSnapshot hotelSnapshot: hotelsSnapshot.getChildren()) {
            Hotel hotel = hotelSnapshot.getValue(Hotel.class);
            presenter.onMarkersLoaded(hotel.getName(), hotel.getLatit(), hotel.getLongit());
        }
        // TODO: call adapter.notifyDataSetChanged();
    }