ChandraMouli Poreddy
ChandraMouli Poreddy

Reputation: 420

How can I fetch particular value(data) from Firebase Database

I have some data in the firebase database as shown in the below figure.

For Inserting I use, mFirebaseInstance.getReference("bus_tracking").child("service_no").child(busId).child("lon").setValue(obj.getLatitude()); I can't able to figure out how to retrive the same value, any suggestions will be appriciated. Thanks in advance.

I want to retrieve lat value.

enter image description here

Upvotes: 0

Views: 39

Answers (1)

Peter Haddad
Peter Haddad

Reputation: 80914

To retrieve lat try the following :

DatabaseReference databaseReference = FirebaseDatabase.getInstance().getReference("bus_tracking").child("service_no");
databaseReference.child(busId).addListenerForSingleValueEvent(new ValueEventListener() {
    @Override
    public void onDataChange(DataSnapshot mainSnapshot) {

       String lat = mainSnapshot.child("lat").getValue(String.class);
    }
    @Override
    public void onCancelled(DatabaseError databaseError) {
     Log.d(TAG,databaseError.getMessage());

    }
});

Add a reference to the node 1 then attach a listener and you will be able to retrieve the value of lat

Upvotes: 1

Related Questions