
Each user registered in the "Users" collection has a field of "latitude" and "longitude" of type double.
Basically, I want to get all the latitude and longitude fields to insert different locations on the map, similar to this, but getting them from Firestore, as well as captioning them with the user's email .title(emailUser):
private DatabaseReference mDatabase;
@Override
protected void onCreate(Bundle savedInstanceState)...
mDatabase = FirebaseDatabase.getInstance().getReference();
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;...
mDatabase.child("usuarios").addValueEventListener(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)).title("Usuario").snippet("BRINDADOR").icon(bitmapDescriptorFromVector(getApplicationContext(),R.drawable.ic_baseline_eco_24));
tmpRealTimeMarkers.add(mMap.addMarker(markerOptions));
}
realTimeMarkers.clear();
realTimeMarkers.addAll(tmpRealTimeMarkers);
}
@Override
public void onCancelled(@NonNull DatabaseError error) {
}
});
