I am drawing a route between two markers, and I want to save that route. To do that I saved the ArrayList containing the lat and lng in the Firebase database. But I am having problems retrieving the waypoints. This is how I inserted:
@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);
}
When retrieving the data, I tried to do the following:
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());
}
}