0
I have this structure at Firebase. And I need to capture all the latitudes and longitudes that are inside each key, I did a test and it’s working if I put this data in a folder without the key it shows the marker on the map without problems, but just one, I want to capture and add all of them as markers on the map, How can I do it? for?
DatabaseReference ref = FirebaseDatabase.getInstance().getReference();
ref.child("uploads").addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
if (dataSnapshot.exists()) {
double location_left = (dataSnapshot.child("latitude").getValue(Double.class));
double location_right = Double.valueOf(dataSnapshot.child("longitude").getValue(Double.class));
LatLng local = new LatLng(location_left, location_right);
mMap.addMarker(new MarkerOptions().position(local).title("Novo Marcador"));
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(local, 18));
} else {
Log.i("MeuLOG", "erro na captura");
}
}
Iamluc, thanks for the tip, but for me it didn’t work, is giving null error Object Reference in the two gets, it’s not finding the object, what’s wrong? if it is by my code above placing Child in an example folder I created called "up" where it contains only 1 latitude and longitude data it works, problem in key will be?
– FranciscoM
Using your code and using a Log. v("log",""+local); It captures all the data that has latitude and longitude and prints for me in the logcat. But after opening the map, where you should add the markers on the map, it closes the app and shows in the logcat this>> Attempt to invoke virtual method 'double java.lang.Double.doubleValue()' on a null Object Reference
– FranciscoM
Where are you putting the bookmark addition code?
– itscorey
I think the correct thing would be to open the map first and then take the data from firebase to add the markers on the map.
– itscorey
The marker addition code is in the code above the question, that’s it, I have the Showmap class that contains the map where it locates and points to my current location and after that the code above where it searches the Firebase data and should add the markers on the map, but does not end up doing, I ask you need get/set entity to perform this procedure, or that is wrong. And I have in the main a button that Intent to the map.
– FranciscoM