I'm trying to get all the markers from my database, I have them stored this way
Now, I create two arraylists of markers, one to add all those markers and then pass it to the other one in order to delete them (I'm trying to refresh the markers in realtime as they show in the map).
But I have tried this to show the markers and it seems it shows me just the first one but not iterate through all the children. Here is what I have tried:
@Override
public void onMapReady(final GoogleMap googleMap) {
mMap = googleMap;
mDatabase.child("usuarios").addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
for (Marker marker : realTimeMarkers) {
marker.remove();
}
for(DataSnapshot snapshot : dataSnapshot.getChildren()){
MapsPojo mp = snapshot.getValue(MapsPojo.class);
Double latitud = mp.getLatitud();
Double longitud = mp.getLongitud();
MarkerOptions markerOptions = new MarkerOptions();
markerOptions.position(new LatLng(latitud,longitud));
markerOptions.snippet("ID: "+snapshot.getKey());
tmpRealTimeMarkers.add(mMap.addMarker(markerOptions));
}
realTimeMarkers.clear();
realTimeMarkers.addAll(tmpRealTimeMarkers);
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
}
where realTimeMarkers and tmpRealTimeMarkers:
private ArrayList<Marker> tmpRealTimeMarkers = new ArrayList<Marker>();
private ArrayList<Marker> realTimeMarkers = new ArrayList<Marker>();
Also the hint is not there, I run the debugger and it seems it's not entering in my foreach
to fetch all the latitudes and longitudes.