在Android中使用GeoFire尝试获取数据时无法进入ValueEventListener

时间:2019-08-02 17:56:34

标签: java android firebase firebase-realtime-database geofire

我正在尝试使用GeoFire调用已保存的数据,但是没有尝试获取单个对象..试图遍历许多项。这是我正在使用的代码:

    public void gettingStationData() {
        Log.e("where are we now", "getting station data function");
        DatabaseReference mDatabaseReference = FirebaseDatabase.getInstance().getReference().child("station");
        mDatabaseReference.child("bus").addValueEventListener(new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot snapshot) {
                Log.e("where are we now", "started on datachange");
                DatabaseError databaseError = null;
                Log.d("the error ", databaseError.getMessage());
                for (DataSnapshot child : snapshot.getChildren()) {
                    Log.e("where are we now", "started the loop");
                    String theName = String.valueOf(child.getValue());
                    Double theLat = (Double) child.child(theName).child("l").child("0").getValue();
                    Double theLong = (Double) child.child(theName).child("l").child("1").getValue();
                    LatLng newBusStationLocation = new LatLng(theLat, theLong);
                    setStationMarker(newBusStationLocation, theName);
                    Log.e("fetched data", String.valueOf(newBusStationLocation));
                }
            }

            @Override
            public void onCancelled(DatabaseError databaseError) {
            }
        });
    }

如您所见,我已经使用Log方法来调试过程。 Log.e("where are we now", "getting station data function");Log.e("where are we now", "started on datachange");均已显示,但是一旦进入循环,就显示了。什么都没有出现,这意味着循环甚至还没有开始。

这是我的数据库的样子:

enter image description here

0 个答案:

没有答案