[英]Firebase realtime database: Is there a way to get value from different node?
My data structure is like this and what I want to do is to get value from different node. 我的数据结构是这样的,我要做的就是从不同的节点获取价值。
root
|__data__people___name1:...
| |_name2:...
| |_name3:...
| ...
|_location__latitude:...
|_longitude:...
Now I want to get location's value (LatLng that is saved earlier) when people's child is added. 现在,我想在添加人的孩子时获取位置的值(之前保存的LatLng)。 But what I know is to get the value that is added. 但是我知道的是获得增加的价值。 Is there a way to refer to different node value? 有没有办法引用不同的节点值?
data.child("people").addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
//get location's value here
}
}
Also, could you kindly tell me how to get LatLng
from database and assign it to LatLng
? 另外,您能告诉我如何从数据库中获取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.