![](/img/trans.png)
[英]How to fetch the data from different node from Firebase realtime database?
[英]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.