【发布时间】:2018-06-29 10:23:20
【问题描述】:
我正在尝试从 android 中的 firebase 实时数据库中读取数据 (出于某种原因,FireBase 对位置数据进行排序,然后对 VideoEntry 进行排序,但我认为无论如何都是正确的......根据生成的 json)
如果您需要,这就是我添加节点的方式:
submitVideoButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String locationName = locationInput.getText().toString();
double lat = Double.parseDouble(latInput.getText().toString());
double lon = Double.parseDouble(longInput.getText().toString());
String userid = mFirebaseUser.getEmail().substring(0, mFirebaseUser.getEmail().indexOf("@"));
String cleanUserId = userid.replaceAll("\\W", "");
updateUserInfo(cleanUserId, mFirebaseUser.getEmail(), "nsaofdhiqo3", locationName, lat, lon);
}
});
}
private void updateUserInfo(String userId, String email, String videoId, String locName, double lat, double lon) {
LocationData location = new LocationData(locName,lat,lon);
VideoEntry videoEntry = new VideoEntry(videoId,location);
UserData user = new UserData(email, videoEntry);
mDatabaseRef.child("users").child(userId).setValue(user);
}
{
"users" : {
"valentinogiuseppe00" : {
"mName" : "valentino.giuseppe00@gmail.com",
"mVideoEntry" : {
"mLocationData" : {
"mLatitude" : 58,
"mLongitude" : 10,
"mName" : "locationName"
},
"mVideoId" : "nsaofdhiqo3"
}
}
}
}
这是我迄今为止尝试过的:
databaseRef.addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(@NonNull DataSnapshot dataSnapshot, @Nullable String s) {
double lat = 0.0, lon = 0.0;
String locName = null;
String fVideoId = null, videoName = null;
String userName = null;
//TODO Need to re-structure the to add markers
for (DataSnapshot userSnapshot : dataSnapshot.getChildren()) {
Log.d(TAG, "userSnapShot children #:" + userSnapshot.getChildrenCount());
userName = userSnapshot.child(cleanUserId).getValue(String.class);
for (DataSnapshot videoSnapShot : dataSnapshot.getChildren()) {
Log.d(TAG, "videoSnapShot children #:" + videoSnapShot.getChildrenCount());
fVideoId = videoSnapShot.child("videoId").getValue(String.class);
// videoName = videoSnapShot.child("").getValue(String.class);
for (DataSnapshot locationSnapShot : dataSnapshot.getChildren()) {
Log.d(TAG, "locationSnapShot children #:" + (locationSnapShot.getChildrenCount()));
lat = locationSnapShot.child("mLatitude").getValue(Double.class);
lon = locationSnapShot.child("mLongitude").getValue(Double.class);
}
}
}
}
如果您需要我的其他东西,请告诉我。
我遗漏了一些东西,因为我可以看到生成的地图以及其中的所有值 感谢各位开发者
【问题讨论】:
-
你需要获取mLLocationData里面的值吗?
-
是的,简而言之,我有 3 个模型用户、视频和位置。我需要这些价值观。特别是位置,因为我正在使用地图。 (你能告诉我关于节点顺序的图形错误的任何事情吗)
标签: java android firebase firebase-realtime-database