答案 0 :(得分:1)
假设DRIVERID
是Firebase root的直接子项,要获取这些值,请使用以下代码:
DatabaseReference rootRef = FirebaseDatabase.getInstance().getReference();
DatabaseReference yourRef = rootRef.child("DRIVERID").child("LatLng");
ValueEventListener eventListener = new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
double Lat = dataSnapshot.child("Lat").getValue(Double.class);
double Lng = dataSnapshot.child("Lng").getValue(Double.class);
Log.d("TAG", Lat + " / " + Lng);
}
@Override
public void onCancelled(DatabaseError databaseError) {}
};
yourRef.addListenerForSingleValueEvent(eventListener);
输出将是:
22.582798 / 88.35998
要获得Compass
,请使用以下代码:
DatabaseReference rootRef = FirebaseDatabase.getInstance().getReference();
DatabaseReference yourRef = rootRef.child("DRIVERID");
ValueEventListener eventListener = new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
double Compasss = = dataSnapshot.child("Compasss").getValue(Double.class);
double Lat = dataSnapshot.child("LatLng").child("Lat").getValue(Double.class);
double Lng = dataSnapshot.child("LatLng").child("Lng").getValue(Double.class);
Log.d("TAG", Compasss + " / " + Lat + " / " + Lng);
}
@Override
public void onCancelled(DatabaseError databaseError) {}
};
yourRef.addListenerForSingleValueEvent(eventListener);
输出将是:
54.5750122070312 / 22.582798 / 88.35998
适用于OP的代码行是:
HashMap Compasss = (HashMap) dataSnapshot.getValue(Boolean.parseBoolean("Compasss"));
答案 1 :(得分:0)
在您的案例中使用var chartHeight = 290
var minPercentage = 5
var myHeight = window.innerHeight
console.log(myHeight)
if (myHeight < 800) {
console.log('ding')
chartHeight = 260
minPercentage = 10
} else if (myHeight > 980) {
chartHeight = 320
}
之类的命名节点查询firebase将在获得对DRIVERID
节点的引用后传递子名称。
DRIVERID
您可以查看此answer
答案 2 :(得分:0)
我建议创建2个Java类:
然后您就可以使用:
DatabaseReference rootRef = FirebaseDatabase.getInstance().getReference().child("DRIVERID");
ValueEventListener eventListener = new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
Driver driver = datasnapshot.getValue(Driver.class);
//your data would be stored in this driver variable
}
@Override
public void onCancelled(DatabaseError databaseError) {}
};
rootRef.addListenerForSingleValueEvent(eventListener);