簡體   English   中英

Firebase實時數據庫:有沒有辦法從其他節點獲取價值?

[英]Firebase realtime database: Is there a way to get value from different node?

我的數據結構是這樣的,我要做的就是從不同的節點獲取價值。

root
  |__data__people___name1:...
         |        |_name2:...
         |        |_name3:...
         |         ...
         |_location__latitude:...
                   |_longitude:...

現在,我想在添加人的孩子時獲取位置的值(之前保存的LatLng)。 但是我知道的是獲得增加的價值。 有沒有辦法引用不同的節點值?

data.child("people").addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
            //get location's value here
            }
        }

另外,您能告訴我如何從數據庫中獲取LatLng並將其分配給LatLng嗎?

data.addValueEventListener(new ValueEventListener() {
    @Override
    public void onDataChange(@NonNull DataSnapshot dataSnapshot) 
        {
           //This loops through the people node
           for( DataSnapshot snao : dataSnapshot.child("people").getChildren() )
           {}

           //get location's value here. Loops through Child nodes
           for( DataSnapshot locSnap : dataSnapshot.child("location").getChildren() )
           {}

           // OR for location
           double lat = (double)dataSnapshot.child("location").child("latitude").getValue();
           double lng = (double)dataSnapshot.child("location").child("longitude").getValue();
        }
    }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM