【发布时间】:2017-10-23 14:39:44
【问题描述】:
我正在两个标记之间绘制一条路线,我想保存该路线。为此,我将包含 lat 和 lng 的 ArrayList 保存在 Firebase 数据库中。但我在检索航点时遇到问题。我是这样插入的:
@Override
protected void onPostExecute(List<List<HashMap<String, String>>> result) {
ArrayList points = null;
PolylineOptions lineOptions = null;
MarkerOptions markerOptions = new MarkerOptions();
for (int i = 0; i < result.size(); i++) {
points = new ArrayList();
lineOptions = new PolylineOptions();
List<HashMap<String, String>> path = result.get(i);
for (int j = 0; j < path.size(); j++) {
HashMap<String, String> point = path.get(j);
double lat = Double.parseDouble(point.get("lat"));
double lng = Double.parseDouble(point.get("lng"));
LatLng position = new LatLng(lat, lng);
points.add(position);
}
lineOptions.addAll(points);
lineOptions.width(12);
lineOptions.color(Color.RED);
lineOptions.geodesic(true);
database.child("Route").child("route").setValue(points);
}
mMap.addPolyline(lineOptions);
}
在检索数据时,我尝试执行以下操作:
userRef.child("Route").child("route).addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
ArrayList ids = null;
for (DataSnapshot childData : dataSnapshot.getChildren()) {
ids.add(childData.getValue());
}
}
【问题讨论】:
-
您可能想使用 POJO 来阅读内容。
标签: android firebase firebase-realtime-database