Android用firebase,如何推送儿童数据?

时间:2016-04-27 16:37:18

标签: android firebase

如何将push()添加到航点儿童?无法做到正确..

    Map mWaypoints = new HashMap();
    mWaypoints.put("latitude", mCurrentLatlngOnCreate.latitude);
    mWaypoints.put("longitude", mCurrentLatlngOnCreate.longitude);

    Map mParent = new HashMap();
    mParent.put("routeID", "my route id");
    mParent.put("routeName", "my route name");
    mParent.put("Waypoints", mWaypoints);

    myFirebaseRef.push().setValue(mParent);

这是当前的结果,但希望将推送ID设置在Waypoints之下。

    -KGNWnjgXPC0kHYiOKG7
       Waypoints        // <---  Want to get the unique below here
          latitude: 31
          longitude: 421
       routeID: "my route id"
       routeName: "my route name"

1 个答案:

答案 0 :(得分:8)

push()是纯客户端操作,您可以单独调用。所以:

Map mWaypoints = new HashMap();
mWaypoints.put("latitude", mCurrentLatlngOnCreate.latitude);
mWaypoints.put("longitude", mCurrentLatlngOnCreate.longitude);

String key = myFirebaseRef.push().getKey();
Map mWayPointsMap = new HashMap();
mWayPointsMap.put(key, mWayPoints);

Map mParent = new HashMap();
mParent.put("routeID", "my route id");
mParent.put("routeName", "my route name");
mParent.put("Waypoints", mWayPointsMap);

myFirebaseRef.push().setValue(mParent);