I can't get specific data from Firebase (Java)











up vote
3
down vote

favorite












I'm doing an application where I need to go in my firebase to get Latitude and Longitude. I don't have any problem to put the Latlng in firebase but i can't get it back. this is what it looks like :



my firebase.



And this is the code when I put them in firebase



Ajouter.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

mProgress.setTitle("Le point se charge");
mProgress.setMessage("Merci de patientez, ce ne sera pas long");
mProgress.show();
mAuth = FirebaseAuth.getInstance();
FirebaseUser user = mAuth.getCurrentUser();
mFirebaseDatabase = FirebaseDatabase.getInstance();
mMarkDatabase = mFirebaseDatabase.getReference();
final String key = mMarkDatabase.child("Pins").push().getKey();

final StorageReference ref = mStorage.child("Photos/" + UUID.randomUUID().toString());
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte data = baos.toByteArray();
UploadTask uploadTask = ref.putBytes(data);
uploadTask = ref.putFile(ImageUri);
Task<Uri> urltask = uploadTask.continueWithTask(new Continuation<UploadTask.TaskSnapshot, Task<Uri>>() {
@Override
public Task<Uri> then(@NonNull Task<UploadTask.TaskSnapshot> task) throws Exception {
if (!task.isSuccessful()) {
throw task.getException();
}

return ref.getDownloadUrl();
}
}).addOnCompleteListener(new OnCompleteListener<Uri>() {
@Override
public void onComplete(@NonNull Task<Uri> task) {
if (task.isSuccessful()) {

downloadUrl = task.getResult();
downloadUrlTxt = downloadUrl.toString();

//uploadImage();
String lon = Double.toString(Longitude);
String lat = Double.toString(Latitude);
String txt = TxtAout.getText().toString();
switch (spinner.getSelectedItemPosition()){
case 0 :
item.put("ImageUrl", ""+downloadUrlTxt);
item.put("Longitude ", lon);
item.put("Latitude", lat);
item.put("Description", txt);
mMarkDatabase.child("Pins").child("Poubelle").child(key).setValue(item);
break;
case 1 :
item.put("ImageUrl", ""+downloadUrlTxt);
item.put("Longitude ", lon);
item.put("Latitude", lat);
item.put("Description", txt);
mMarkDatabase.child("Pins").child("BlueLy").child(key).setValue(item);
break;
case 2 :
item.put("ImageUrl", ""+downloadUrlTxt);
item.put("Longitude ", lon);
item.put("Latitude", lat);
item.put("Description", txt);
mMarkDatabase.child("Pins").child("Parcs a chiens").child(key).setValue(item);
break;
case 3 :
item.put("ImageUrl", ""+downloadUrlTxt);
item.put("Longitude ", lon);
item.put("Latitude", lat);
item.put("Description", txt);
mMarkDatabase.child("Pins").child("Collecte de vetements").child(key).setValue(item);
break;
default :
Toast.makeText(LocalisationOnlyVert.this, "Erreur, merci de recommencer", Toast.LENGTH_SHORT).show();
}

mProgress.dismiss();
Toast.makeText(LocalisationOnlyVert.this, "Merci de votre ajout !", Toast.LENGTH_SHORT).show();
TxtAout.setText("");
Intent Retour = new Intent (LocalisationOnlyVert.this, OnlyVert.class);
startActivity(Retour);
Toast.makeText(LocalisationOnlyVert.this, ""+downloadUrlTxt , Toast.LENGTH_LONG).show();
}
}
});

}
});


I don't know how to separate my latitude, my longitude, description and URL. I don't know what to do anymore.



Edit : After what you send me i tried :



BtnMarker.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mDatabase = FirebaseDatabase.getInstance().getReference();
mDatabase.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
for(DataSnapshot snapshot: dataSnapshot.getChildren()){

HandleData.Pin pin = snapshot.getValue(HandleData.Pin.class);
Toast.makeText(OnlyVert.this, pin.getLat(), Toast.LENGTH_SHORT).show();

}


}

@Override
public void onCancelled(@NonNull DatabaseError databaseError) {

}
});
}


The mistake is com.google.firebase.database.DatabaseException: Class com.example.alexandre.onlyvert.HandleData$Pin does not define a no-argument constructor. If you are using ProGuard, make sure these constructors are not stripped.










share|improve this question




















  • 2




    Post code instead of pictures
    – CodeMatrix
    Nov 19 at 14:16










  • what code you are using to fetch the data ?
    – Har Kal
    Nov 19 at 14:30










  • Yes i'm sorry it's done
    – Alexandre
    Nov 19 at 14:30










  • problem resolved?
    – Har Kal
    Nov 19 at 14:32










  • I have tried a couple of things but nothing seems to work as i want. Do you have an idea of what's best to get them ?
    – Alexandre
    Nov 19 at 14:35

















up vote
3
down vote

favorite












I'm doing an application where I need to go in my firebase to get Latitude and Longitude. I don't have any problem to put the Latlng in firebase but i can't get it back. this is what it looks like :



my firebase.



And this is the code when I put them in firebase



Ajouter.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

mProgress.setTitle("Le point se charge");
mProgress.setMessage("Merci de patientez, ce ne sera pas long");
mProgress.show();
mAuth = FirebaseAuth.getInstance();
FirebaseUser user = mAuth.getCurrentUser();
mFirebaseDatabase = FirebaseDatabase.getInstance();
mMarkDatabase = mFirebaseDatabase.getReference();
final String key = mMarkDatabase.child("Pins").push().getKey();

final StorageReference ref = mStorage.child("Photos/" + UUID.randomUUID().toString());
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte data = baos.toByteArray();
UploadTask uploadTask = ref.putBytes(data);
uploadTask = ref.putFile(ImageUri);
Task<Uri> urltask = uploadTask.continueWithTask(new Continuation<UploadTask.TaskSnapshot, Task<Uri>>() {
@Override
public Task<Uri> then(@NonNull Task<UploadTask.TaskSnapshot> task) throws Exception {
if (!task.isSuccessful()) {
throw task.getException();
}

return ref.getDownloadUrl();
}
}).addOnCompleteListener(new OnCompleteListener<Uri>() {
@Override
public void onComplete(@NonNull Task<Uri> task) {
if (task.isSuccessful()) {

downloadUrl = task.getResult();
downloadUrlTxt = downloadUrl.toString();

//uploadImage();
String lon = Double.toString(Longitude);
String lat = Double.toString(Latitude);
String txt = TxtAout.getText().toString();
switch (spinner.getSelectedItemPosition()){
case 0 :
item.put("ImageUrl", ""+downloadUrlTxt);
item.put("Longitude ", lon);
item.put("Latitude", lat);
item.put("Description", txt);
mMarkDatabase.child("Pins").child("Poubelle").child(key).setValue(item);
break;
case 1 :
item.put("ImageUrl", ""+downloadUrlTxt);
item.put("Longitude ", lon);
item.put("Latitude", lat);
item.put("Description", txt);
mMarkDatabase.child("Pins").child("BlueLy").child(key).setValue(item);
break;
case 2 :
item.put("ImageUrl", ""+downloadUrlTxt);
item.put("Longitude ", lon);
item.put("Latitude", lat);
item.put("Description", txt);
mMarkDatabase.child("Pins").child("Parcs a chiens").child(key).setValue(item);
break;
case 3 :
item.put("ImageUrl", ""+downloadUrlTxt);
item.put("Longitude ", lon);
item.put("Latitude", lat);
item.put("Description", txt);
mMarkDatabase.child("Pins").child("Collecte de vetements").child(key).setValue(item);
break;
default :
Toast.makeText(LocalisationOnlyVert.this, "Erreur, merci de recommencer", Toast.LENGTH_SHORT).show();
}

mProgress.dismiss();
Toast.makeText(LocalisationOnlyVert.this, "Merci de votre ajout !", Toast.LENGTH_SHORT).show();
TxtAout.setText("");
Intent Retour = new Intent (LocalisationOnlyVert.this, OnlyVert.class);
startActivity(Retour);
Toast.makeText(LocalisationOnlyVert.this, ""+downloadUrlTxt , Toast.LENGTH_LONG).show();
}
}
});

}
});


I don't know how to separate my latitude, my longitude, description and URL. I don't know what to do anymore.



Edit : After what you send me i tried :



BtnMarker.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mDatabase = FirebaseDatabase.getInstance().getReference();
mDatabase.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
for(DataSnapshot snapshot: dataSnapshot.getChildren()){

HandleData.Pin pin = snapshot.getValue(HandleData.Pin.class);
Toast.makeText(OnlyVert.this, pin.getLat(), Toast.LENGTH_SHORT).show();

}


}

@Override
public void onCancelled(@NonNull DatabaseError databaseError) {

}
});
}


The mistake is com.google.firebase.database.DatabaseException: Class com.example.alexandre.onlyvert.HandleData$Pin does not define a no-argument constructor. If you are using ProGuard, make sure these constructors are not stripped.










share|improve this question




















  • 2




    Post code instead of pictures
    – CodeMatrix
    Nov 19 at 14:16










  • what code you are using to fetch the data ?
    – Har Kal
    Nov 19 at 14:30










  • Yes i'm sorry it's done
    – Alexandre
    Nov 19 at 14:30










  • problem resolved?
    – Har Kal
    Nov 19 at 14:32










  • I have tried a couple of things but nothing seems to work as i want. Do you have an idea of what's best to get them ?
    – Alexandre
    Nov 19 at 14:35















up vote
3
down vote

favorite









up vote
3
down vote

favorite











I'm doing an application where I need to go in my firebase to get Latitude and Longitude. I don't have any problem to put the Latlng in firebase but i can't get it back. this is what it looks like :



my firebase.



And this is the code when I put them in firebase



Ajouter.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

mProgress.setTitle("Le point se charge");
mProgress.setMessage("Merci de patientez, ce ne sera pas long");
mProgress.show();
mAuth = FirebaseAuth.getInstance();
FirebaseUser user = mAuth.getCurrentUser();
mFirebaseDatabase = FirebaseDatabase.getInstance();
mMarkDatabase = mFirebaseDatabase.getReference();
final String key = mMarkDatabase.child("Pins").push().getKey();

final StorageReference ref = mStorage.child("Photos/" + UUID.randomUUID().toString());
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte data = baos.toByteArray();
UploadTask uploadTask = ref.putBytes(data);
uploadTask = ref.putFile(ImageUri);
Task<Uri> urltask = uploadTask.continueWithTask(new Continuation<UploadTask.TaskSnapshot, Task<Uri>>() {
@Override
public Task<Uri> then(@NonNull Task<UploadTask.TaskSnapshot> task) throws Exception {
if (!task.isSuccessful()) {
throw task.getException();
}

return ref.getDownloadUrl();
}
}).addOnCompleteListener(new OnCompleteListener<Uri>() {
@Override
public void onComplete(@NonNull Task<Uri> task) {
if (task.isSuccessful()) {

downloadUrl = task.getResult();
downloadUrlTxt = downloadUrl.toString();

//uploadImage();
String lon = Double.toString(Longitude);
String lat = Double.toString(Latitude);
String txt = TxtAout.getText().toString();
switch (spinner.getSelectedItemPosition()){
case 0 :
item.put("ImageUrl", ""+downloadUrlTxt);
item.put("Longitude ", lon);
item.put("Latitude", lat);
item.put("Description", txt);
mMarkDatabase.child("Pins").child("Poubelle").child(key).setValue(item);
break;
case 1 :
item.put("ImageUrl", ""+downloadUrlTxt);
item.put("Longitude ", lon);
item.put("Latitude", lat);
item.put("Description", txt);
mMarkDatabase.child("Pins").child("BlueLy").child(key).setValue(item);
break;
case 2 :
item.put("ImageUrl", ""+downloadUrlTxt);
item.put("Longitude ", lon);
item.put("Latitude", lat);
item.put("Description", txt);
mMarkDatabase.child("Pins").child("Parcs a chiens").child(key).setValue(item);
break;
case 3 :
item.put("ImageUrl", ""+downloadUrlTxt);
item.put("Longitude ", lon);
item.put("Latitude", lat);
item.put("Description", txt);
mMarkDatabase.child("Pins").child("Collecte de vetements").child(key).setValue(item);
break;
default :
Toast.makeText(LocalisationOnlyVert.this, "Erreur, merci de recommencer", Toast.LENGTH_SHORT).show();
}

mProgress.dismiss();
Toast.makeText(LocalisationOnlyVert.this, "Merci de votre ajout !", Toast.LENGTH_SHORT).show();
TxtAout.setText("");
Intent Retour = new Intent (LocalisationOnlyVert.this, OnlyVert.class);
startActivity(Retour);
Toast.makeText(LocalisationOnlyVert.this, ""+downloadUrlTxt , Toast.LENGTH_LONG).show();
}
}
});

}
});


I don't know how to separate my latitude, my longitude, description and URL. I don't know what to do anymore.



Edit : After what you send me i tried :



BtnMarker.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mDatabase = FirebaseDatabase.getInstance().getReference();
mDatabase.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
for(DataSnapshot snapshot: dataSnapshot.getChildren()){

HandleData.Pin pin = snapshot.getValue(HandleData.Pin.class);
Toast.makeText(OnlyVert.this, pin.getLat(), Toast.LENGTH_SHORT).show();

}


}

@Override
public void onCancelled(@NonNull DatabaseError databaseError) {

}
});
}


The mistake is com.google.firebase.database.DatabaseException: Class com.example.alexandre.onlyvert.HandleData$Pin does not define a no-argument constructor. If you are using ProGuard, make sure these constructors are not stripped.










share|improve this question















I'm doing an application where I need to go in my firebase to get Latitude and Longitude. I don't have any problem to put the Latlng in firebase but i can't get it back. this is what it looks like :



my firebase.



And this is the code when I put them in firebase



Ajouter.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

mProgress.setTitle("Le point se charge");
mProgress.setMessage("Merci de patientez, ce ne sera pas long");
mProgress.show();
mAuth = FirebaseAuth.getInstance();
FirebaseUser user = mAuth.getCurrentUser();
mFirebaseDatabase = FirebaseDatabase.getInstance();
mMarkDatabase = mFirebaseDatabase.getReference();
final String key = mMarkDatabase.child("Pins").push().getKey();

final StorageReference ref = mStorage.child("Photos/" + UUID.randomUUID().toString());
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte data = baos.toByteArray();
UploadTask uploadTask = ref.putBytes(data);
uploadTask = ref.putFile(ImageUri);
Task<Uri> urltask = uploadTask.continueWithTask(new Continuation<UploadTask.TaskSnapshot, Task<Uri>>() {
@Override
public Task<Uri> then(@NonNull Task<UploadTask.TaskSnapshot> task) throws Exception {
if (!task.isSuccessful()) {
throw task.getException();
}

return ref.getDownloadUrl();
}
}).addOnCompleteListener(new OnCompleteListener<Uri>() {
@Override
public void onComplete(@NonNull Task<Uri> task) {
if (task.isSuccessful()) {

downloadUrl = task.getResult();
downloadUrlTxt = downloadUrl.toString();

//uploadImage();
String lon = Double.toString(Longitude);
String lat = Double.toString(Latitude);
String txt = TxtAout.getText().toString();
switch (spinner.getSelectedItemPosition()){
case 0 :
item.put("ImageUrl", ""+downloadUrlTxt);
item.put("Longitude ", lon);
item.put("Latitude", lat);
item.put("Description", txt);
mMarkDatabase.child("Pins").child("Poubelle").child(key).setValue(item);
break;
case 1 :
item.put("ImageUrl", ""+downloadUrlTxt);
item.put("Longitude ", lon);
item.put("Latitude", lat);
item.put("Description", txt);
mMarkDatabase.child("Pins").child("BlueLy").child(key).setValue(item);
break;
case 2 :
item.put("ImageUrl", ""+downloadUrlTxt);
item.put("Longitude ", lon);
item.put("Latitude", lat);
item.put("Description", txt);
mMarkDatabase.child("Pins").child("Parcs a chiens").child(key).setValue(item);
break;
case 3 :
item.put("ImageUrl", ""+downloadUrlTxt);
item.put("Longitude ", lon);
item.put("Latitude", lat);
item.put("Description", txt);
mMarkDatabase.child("Pins").child("Collecte de vetements").child(key).setValue(item);
break;
default :
Toast.makeText(LocalisationOnlyVert.this, "Erreur, merci de recommencer", Toast.LENGTH_SHORT).show();
}

mProgress.dismiss();
Toast.makeText(LocalisationOnlyVert.this, "Merci de votre ajout !", Toast.LENGTH_SHORT).show();
TxtAout.setText("");
Intent Retour = new Intent (LocalisationOnlyVert.this, OnlyVert.class);
startActivity(Retour);
Toast.makeText(LocalisationOnlyVert.this, ""+downloadUrlTxt , Toast.LENGTH_LONG).show();
}
}
});

}
});


I don't know how to separate my latitude, my longitude, description and URL. I don't know what to do anymore.



Edit : After what you send me i tried :



BtnMarker.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mDatabase = FirebaseDatabase.getInstance().getReference();
mDatabase.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
for(DataSnapshot snapshot: dataSnapshot.getChildren()){

HandleData.Pin pin = snapshot.getValue(HandleData.Pin.class);
Toast.makeText(OnlyVert.this, pin.getLat(), Toast.LENGTH_SHORT).show();

}


}

@Override
public void onCancelled(@NonNull DatabaseError databaseError) {

}
});
}


The mistake is com.google.firebase.database.DatabaseException: Class com.example.alexandre.onlyvert.HandleData$Pin does not define a no-argument constructor. If you are using ProGuard, make sure these constructors are not stripped.







java firebase firebase-realtime-database






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 19 at 17:30

























asked Nov 19 at 14:14









Alexandre

164




164








  • 2




    Post code instead of pictures
    – CodeMatrix
    Nov 19 at 14:16










  • what code you are using to fetch the data ?
    – Har Kal
    Nov 19 at 14:30










  • Yes i'm sorry it's done
    – Alexandre
    Nov 19 at 14:30










  • problem resolved?
    – Har Kal
    Nov 19 at 14:32










  • I have tried a couple of things but nothing seems to work as i want. Do you have an idea of what's best to get them ?
    – Alexandre
    Nov 19 at 14:35
















  • 2




    Post code instead of pictures
    – CodeMatrix
    Nov 19 at 14:16










  • what code you are using to fetch the data ?
    – Har Kal
    Nov 19 at 14:30










  • Yes i'm sorry it's done
    – Alexandre
    Nov 19 at 14:30










  • problem resolved?
    – Har Kal
    Nov 19 at 14:32










  • I have tried a couple of things but nothing seems to work as i want. Do you have an idea of what's best to get them ?
    – Alexandre
    Nov 19 at 14:35










2




2




Post code instead of pictures
– CodeMatrix
Nov 19 at 14:16




Post code instead of pictures
– CodeMatrix
Nov 19 at 14:16












what code you are using to fetch the data ?
– Har Kal
Nov 19 at 14:30




what code you are using to fetch the data ?
– Har Kal
Nov 19 at 14:30












Yes i'm sorry it's done
– Alexandre
Nov 19 at 14:30




Yes i'm sorry it's done
– Alexandre
Nov 19 at 14:30












problem resolved?
– Har Kal
Nov 19 at 14:32




problem resolved?
– Har Kal
Nov 19 at 14:32












I have tried a couple of things but nothing seems to work as i want. Do you have an idea of what's best to get them ?
– Alexandre
Nov 19 at 14:35






I have tried a couple of things but nothing seems to work as i want. Do you have an idea of what's best to get them ?
– Alexandre
Nov 19 at 14:35














2 Answers
2






active

oldest

votes

















up vote
0
down vote













Use this following class it has got everything you want



you can set data using this and track events too



you can get data using this and again track the events



 public class HandleData {

private OnDataSet onDataSet;
private OnDataCallBack onDataCallBack;

public void setOnDataSet(OnDataSet onDataSet) {
this.onDataSet = onDataSet;
}

public void setOnDataCallBack(OnDataCallBack onDataCallBack) {
this.onDataCallBack = onDataCallBack;
}

private FirebaseDatabase firebaseDatabase;

public HandleData() {
firebaseDatabase = FirebaseDatabase.getInstance();
}

public void putData(String specificNode, Pin pin){
DatabaseReference databaseReference = firebaseDatabase.getReference("path/to/node/").child(specificNode);
databaseReference.setValue(pin).addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {
if(onDataSet != null){
onDataSet.onSucess();
}
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
if(onDataSet != null){
onDataSet.onFailed(e.toString());
}
}
});
}

public void readData(String specificNode){
DatabaseReference databaseReference = firebaseDatabase.getReference("path/to/node/").child(specificNode);
databaseReference.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
if(dataSnapshot.exists()){
int initCount = 0;
int totalCount = (int) dataSnapshot.getChildrenCount();
ArrayList<Pin> pins = new ArrayList<>();
for(DataSnapshot snapshot : dataSnapshot.getChildren()){
initCount = initCount +1;
Pin pin = snapshot.getValue(Pin.class);
pins.add(pin);
if(initCount == totalCount){
if(onDataCallBack != null){
onDataCallBack.onSuccess(pins);
}
}

}
}else{
if(onDataCallBack != null){
onDataCallBack.onFailed("no data found in database");
}
}
}

@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
if(onDataCallBack != null){
onDataCallBack.onFailed(databaseError.toString());
}
}
});
}

public class Pin{

private String about;
private String imgUrl;
private String lat;
private String lng;

public Pin() {

}

public Pin(String about, String imgUrl, String lat, String lng) {
this.about = about;
this.imgUrl = imgUrl;
this.lat = lat;
this.lng = lng;
}

public String getAbout() {
return about;
}

public void setAbout(String about) {
this.about = about;
}

public String getImgUrl() {
return imgUrl;
}

public void setImgUrl(String imgUrl) {
this.imgUrl = imgUrl;
}

public String getLat() {
return lat;
}

public void setLat(String lat) {
this.lat = lat;
}

public String getLng() {
return lng;
}

public void setLng(String lng) {
this.lng = lng;
}
}

public interface OnDataSet{
void onSucess();
void onFailed(String error);
}

public interface OnDataCallBack{
void onSuccess(ArrayList<Pin> pins);
void onFailed(String error);
}

}





share|improve this answer























  • Thank you very much, I'll try that in a moment and tell you if it's working :D
    – Alexandre
    Nov 19 at 15:42










  • So i tried your way but i don't really know how everything works
    – Alexandre
    Nov 19 at 17:28










  • go and read the docs => firebase.google.com/docs/database/android/start
    – Har Kal
    Nov 19 at 17:44


















up vote
0
down vote













You have a typo here



item.put("Longitude ", lon);


change it to this



item.put("Longitude", lon);


as that is pushing the key value with " " at your Firebase structure and thats why you can't fetch that value, since a Map needs a Key - Value pair to work and it can't find out the Longitude data.



Also, after changing this, you will need to push new values and delete the ones at your database that are wrong



The logcat exception is pointing out right here



double longitude = Double.parseDouble(map.get("Longitude"));


with this




java.util.Map has generic type parameters




enter image description here



Now , fetching the data.



As I understand, you need to press a button and fetch all LatLang from that node at firebase, let say you have the button Poubelle that gets all the latitude and longitude from that node, that can be done in this way.



        mDatabase = FirebaseDatabase.getInstance().getReference();
DatabaseReference mPoubelleRef = mDatabase.child("Pins").child("Poubelle");

BtnPoubelle.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

mPoubelleRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for(DataSnapshot snapshot: dataSnapshot.getChildren()){
Map<String, String> map = snapshot.getValue(Map.class);
double latitude = Double.parseDouble(map.get("Latitude"));
double longitude = Double.parseDouble(map.get("Longitude"));

//or get the data with a model (is the same thing as above)
YourModel model = snapshot.getValue(YourModel.class);
double latitude = model.getLatitude();
double longitude = model.getLongitude();

}
}

@Override
public void onCancelled(DatabaseError databaseError) {
System.out.println("The read failed: " + databaseError.getCode());
}
});
}


Before retrieving the data, first delete the nodes with




"Longitude " :




or it will fail each time when it tries to get your data.






share|improve this answer























  • I fixed that thanks :D
    – Alexandre
    Nov 19 at 17:32










  • Did all worked fine ?
    – Gastón Saillén
    Nov 19 at 17:42










  • Yes thank you :D
    – Alexandre
    Nov 23 at 9:14










  • If that worked can you mark the answer as correct ? Thanks and have a nice weekend
    – Gastón Saillén
    Nov 23 at 10:02











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53376502%2fi-cant-get-specific-data-from-firebase-java%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
0
down vote













Use this following class it has got everything you want



you can set data using this and track events too



you can get data using this and again track the events



 public class HandleData {

private OnDataSet onDataSet;
private OnDataCallBack onDataCallBack;

public void setOnDataSet(OnDataSet onDataSet) {
this.onDataSet = onDataSet;
}

public void setOnDataCallBack(OnDataCallBack onDataCallBack) {
this.onDataCallBack = onDataCallBack;
}

private FirebaseDatabase firebaseDatabase;

public HandleData() {
firebaseDatabase = FirebaseDatabase.getInstance();
}

public void putData(String specificNode, Pin pin){
DatabaseReference databaseReference = firebaseDatabase.getReference("path/to/node/").child(specificNode);
databaseReference.setValue(pin).addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {
if(onDataSet != null){
onDataSet.onSucess();
}
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
if(onDataSet != null){
onDataSet.onFailed(e.toString());
}
}
});
}

public void readData(String specificNode){
DatabaseReference databaseReference = firebaseDatabase.getReference("path/to/node/").child(specificNode);
databaseReference.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
if(dataSnapshot.exists()){
int initCount = 0;
int totalCount = (int) dataSnapshot.getChildrenCount();
ArrayList<Pin> pins = new ArrayList<>();
for(DataSnapshot snapshot : dataSnapshot.getChildren()){
initCount = initCount +1;
Pin pin = snapshot.getValue(Pin.class);
pins.add(pin);
if(initCount == totalCount){
if(onDataCallBack != null){
onDataCallBack.onSuccess(pins);
}
}

}
}else{
if(onDataCallBack != null){
onDataCallBack.onFailed("no data found in database");
}
}
}

@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
if(onDataCallBack != null){
onDataCallBack.onFailed(databaseError.toString());
}
}
});
}

public class Pin{

private String about;
private String imgUrl;
private String lat;
private String lng;

public Pin() {

}

public Pin(String about, String imgUrl, String lat, String lng) {
this.about = about;
this.imgUrl = imgUrl;
this.lat = lat;
this.lng = lng;
}

public String getAbout() {
return about;
}

public void setAbout(String about) {
this.about = about;
}

public String getImgUrl() {
return imgUrl;
}

public void setImgUrl(String imgUrl) {
this.imgUrl = imgUrl;
}

public String getLat() {
return lat;
}

public void setLat(String lat) {
this.lat = lat;
}

public String getLng() {
return lng;
}

public void setLng(String lng) {
this.lng = lng;
}
}

public interface OnDataSet{
void onSucess();
void onFailed(String error);
}

public interface OnDataCallBack{
void onSuccess(ArrayList<Pin> pins);
void onFailed(String error);
}

}





share|improve this answer























  • Thank you very much, I'll try that in a moment and tell you if it's working :D
    – Alexandre
    Nov 19 at 15:42










  • So i tried your way but i don't really know how everything works
    – Alexandre
    Nov 19 at 17:28










  • go and read the docs => firebase.google.com/docs/database/android/start
    – Har Kal
    Nov 19 at 17:44















up vote
0
down vote













Use this following class it has got everything you want



you can set data using this and track events too



you can get data using this and again track the events



 public class HandleData {

private OnDataSet onDataSet;
private OnDataCallBack onDataCallBack;

public void setOnDataSet(OnDataSet onDataSet) {
this.onDataSet = onDataSet;
}

public void setOnDataCallBack(OnDataCallBack onDataCallBack) {
this.onDataCallBack = onDataCallBack;
}

private FirebaseDatabase firebaseDatabase;

public HandleData() {
firebaseDatabase = FirebaseDatabase.getInstance();
}

public void putData(String specificNode, Pin pin){
DatabaseReference databaseReference = firebaseDatabase.getReference("path/to/node/").child(specificNode);
databaseReference.setValue(pin).addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {
if(onDataSet != null){
onDataSet.onSucess();
}
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
if(onDataSet != null){
onDataSet.onFailed(e.toString());
}
}
});
}

public void readData(String specificNode){
DatabaseReference databaseReference = firebaseDatabase.getReference("path/to/node/").child(specificNode);
databaseReference.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
if(dataSnapshot.exists()){
int initCount = 0;
int totalCount = (int) dataSnapshot.getChildrenCount();
ArrayList<Pin> pins = new ArrayList<>();
for(DataSnapshot snapshot : dataSnapshot.getChildren()){
initCount = initCount +1;
Pin pin = snapshot.getValue(Pin.class);
pins.add(pin);
if(initCount == totalCount){
if(onDataCallBack != null){
onDataCallBack.onSuccess(pins);
}
}

}
}else{
if(onDataCallBack != null){
onDataCallBack.onFailed("no data found in database");
}
}
}

@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
if(onDataCallBack != null){
onDataCallBack.onFailed(databaseError.toString());
}
}
});
}

public class Pin{

private String about;
private String imgUrl;
private String lat;
private String lng;

public Pin() {

}

public Pin(String about, String imgUrl, String lat, String lng) {
this.about = about;
this.imgUrl = imgUrl;
this.lat = lat;
this.lng = lng;
}

public String getAbout() {
return about;
}

public void setAbout(String about) {
this.about = about;
}

public String getImgUrl() {
return imgUrl;
}

public void setImgUrl(String imgUrl) {
this.imgUrl = imgUrl;
}

public String getLat() {
return lat;
}

public void setLat(String lat) {
this.lat = lat;
}

public String getLng() {
return lng;
}

public void setLng(String lng) {
this.lng = lng;
}
}

public interface OnDataSet{
void onSucess();
void onFailed(String error);
}

public interface OnDataCallBack{
void onSuccess(ArrayList<Pin> pins);
void onFailed(String error);
}

}





share|improve this answer























  • Thank you very much, I'll try that in a moment and tell you if it's working :D
    – Alexandre
    Nov 19 at 15:42










  • So i tried your way but i don't really know how everything works
    – Alexandre
    Nov 19 at 17:28










  • go and read the docs => firebase.google.com/docs/database/android/start
    – Har Kal
    Nov 19 at 17:44













up vote
0
down vote










up vote
0
down vote









Use this following class it has got everything you want



you can set data using this and track events too



you can get data using this and again track the events



 public class HandleData {

private OnDataSet onDataSet;
private OnDataCallBack onDataCallBack;

public void setOnDataSet(OnDataSet onDataSet) {
this.onDataSet = onDataSet;
}

public void setOnDataCallBack(OnDataCallBack onDataCallBack) {
this.onDataCallBack = onDataCallBack;
}

private FirebaseDatabase firebaseDatabase;

public HandleData() {
firebaseDatabase = FirebaseDatabase.getInstance();
}

public void putData(String specificNode, Pin pin){
DatabaseReference databaseReference = firebaseDatabase.getReference("path/to/node/").child(specificNode);
databaseReference.setValue(pin).addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {
if(onDataSet != null){
onDataSet.onSucess();
}
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
if(onDataSet != null){
onDataSet.onFailed(e.toString());
}
}
});
}

public void readData(String specificNode){
DatabaseReference databaseReference = firebaseDatabase.getReference("path/to/node/").child(specificNode);
databaseReference.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
if(dataSnapshot.exists()){
int initCount = 0;
int totalCount = (int) dataSnapshot.getChildrenCount();
ArrayList<Pin> pins = new ArrayList<>();
for(DataSnapshot snapshot : dataSnapshot.getChildren()){
initCount = initCount +1;
Pin pin = snapshot.getValue(Pin.class);
pins.add(pin);
if(initCount == totalCount){
if(onDataCallBack != null){
onDataCallBack.onSuccess(pins);
}
}

}
}else{
if(onDataCallBack != null){
onDataCallBack.onFailed("no data found in database");
}
}
}

@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
if(onDataCallBack != null){
onDataCallBack.onFailed(databaseError.toString());
}
}
});
}

public class Pin{

private String about;
private String imgUrl;
private String lat;
private String lng;

public Pin() {

}

public Pin(String about, String imgUrl, String lat, String lng) {
this.about = about;
this.imgUrl = imgUrl;
this.lat = lat;
this.lng = lng;
}

public String getAbout() {
return about;
}

public void setAbout(String about) {
this.about = about;
}

public String getImgUrl() {
return imgUrl;
}

public void setImgUrl(String imgUrl) {
this.imgUrl = imgUrl;
}

public String getLat() {
return lat;
}

public void setLat(String lat) {
this.lat = lat;
}

public String getLng() {
return lng;
}

public void setLng(String lng) {
this.lng = lng;
}
}

public interface OnDataSet{
void onSucess();
void onFailed(String error);
}

public interface OnDataCallBack{
void onSuccess(ArrayList<Pin> pins);
void onFailed(String error);
}

}





share|improve this answer














Use this following class it has got everything you want



you can set data using this and track events too



you can get data using this and again track the events



 public class HandleData {

private OnDataSet onDataSet;
private OnDataCallBack onDataCallBack;

public void setOnDataSet(OnDataSet onDataSet) {
this.onDataSet = onDataSet;
}

public void setOnDataCallBack(OnDataCallBack onDataCallBack) {
this.onDataCallBack = onDataCallBack;
}

private FirebaseDatabase firebaseDatabase;

public HandleData() {
firebaseDatabase = FirebaseDatabase.getInstance();
}

public void putData(String specificNode, Pin pin){
DatabaseReference databaseReference = firebaseDatabase.getReference("path/to/node/").child(specificNode);
databaseReference.setValue(pin).addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {
if(onDataSet != null){
onDataSet.onSucess();
}
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
if(onDataSet != null){
onDataSet.onFailed(e.toString());
}
}
});
}

public void readData(String specificNode){
DatabaseReference databaseReference = firebaseDatabase.getReference("path/to/node/").child(specificNode);
databaseReference.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
if(dataSnapshot.exists()){
int initCount = 0;
int totalCount = (int) dataSnapshot.getChildrenCount();
ArrayList<Pin> pins = new ArrayList<>();
for(DataSnapshot snapshot : dataSnapshot.getChildren()){
initCount = initCount +1;
Pin pin = snapshot.getValue(Pin.class);
pins.add(pin);
if(initCount == totalCount){
if(onDataCallBack != null){
onDataCallBack.onSuccess(pins);
}
}

}
}else{
if(onDataCallBack != null){
onDataCallBack.onFailed("no data found in database");
}
}
}

@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
if(onDataCallBack != null){
onDataCallBack.onFailed(databaseError.toString());
}
}
});
}

public class Pin{

private String about;
private String imgUrl;
private String lat;
private String lng;

public Pin() {

}

public Pin(String about, String imgUrl, String lat, String lng) {
this.about = about;
this.imgUrl = imgUrl;
this.lat = lat;
this.lng = lng;
}

public String getAbout() {
return about;
}

public void setAbout(String about) {
this.about = about;
}

public String getImgUrl() {
return imgUrl;
}

public void setImgUrl(String imgUrl) {
this.imgUrl = imgUrl;
}

public String getLat() {
return lat;
}

public void setLat(String lat) {
this.lat = lat;
}

public String getLng() {
return lng;
}

public void setLng(String lng) {
this.lng = lng;
}
}

public interface OnDataSet{
void onSucess();
void onFailed(String error);
}

public interface OnDataCallBack{
void onSuccess(ArrayList<Pin> pins);
void onFailed(String error);
}

}






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 19 at 15:35









Gastón Saillén

3,0013830




3,0013830










answered Nov 19 at 15:20









Har Kal

590314




590314












  • Thank you very much, I'll try that in a moment and tell you if it's working :D
    – Alexandre
    Nov 19 at 15:42










  • So i tried your way but i don't really know how everything works
    – Alexandre
    Nov 19 at 17:28










  • go and read the docs => firebase.google.com/docs/database/android/start
    – Har Kal
    Nov 19 at 17:44


















  • Thank you very much, I'll try that in a moment and tell you if it's working :D
    – Alexandre
    Nov 19 at 15:42










  • So i tried your way but i don't really know how everything works
    – Alexandre
    Nov 19 at 17:28










  • go and read the docs => firebase.google.com/docs/database/android/start
    – Har Kal
    Nov 19 at 17:44
















Thank you very much, I'll try that in a moment and tell you if it's working :D
– Alexandre
Nov 19 at 15:42




Thank you very much, I'll try that in a moment and tell you if it's working :D
– Alexandre
Nov 19 at 15:42












So i tried your way but i don't really know how everything works
– Alexandre
Nov 19 at 17:28




So i tried your way but i don't really know how everything works
– Alexandre
Nov 19 at 17:28












go and read the docs => firebase.google.com/docs/database/android/start
– Har Kal
Nov 19 at 17:44




go and read the docs => firebase.google.com/docs/database/android/start
– Har Kal
Nov 19 at 17:44












up vote
0
down vote













You have a typo here



item.put("Longitude ", lon);


change it to this



item.put("Longitude", lon);


as that is pushing the key value with " " at your Firebase structure and thats why you can't fetch that value, since a Map needs a Key - Value pair to work and it can't find out the Longitude data.



Also, after changing this, you will need to push new values and delete the ones at your database that are wrong



The logcat exception is pointing out right here



double longitude = Double.parseDouble(map.get("Longitude"));


with this




java.util.Map has generic type parameters




enter image description here



Now , fetching the data.



As I understand, you need to press a button and fetch all LatLang from that node at firebase, let say you have the button Poubelle that gets all the latitude and longitude from that node, that can be done in this way.



        mDatabase = FirebaseDatabase.getInstance().getReference();
DatabaseReference mPoubelleRef = mDatabase.child("Pins").child("Poubelle");

BtnPoubelle.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

mPoubelleRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for(DataSnapshot snapshot: dataSnapshot.getChildren()){
Map<String, String> map = snapshot.getValue(Map.class);
double latitude = Double.parseDouble(map.get("Latitude"));
double longitude = Double.parseDouble(map.get("Longitude"));

//or get the data with a model (is the same thing as above)
YourModel model = snapshot.getValue(YourModel.class);
double latitude = model.getLatitude();
double longitude = model.getLongitude();

}
}

@Override
public void onCancelled(DatabaseError databaseError) {
System.out.println("The read failed: " + databaseError.getCode());
}
});
}


Before retrieving the data, first delete the nodes with




"Longitude " :




or it will fail each time when it tries to get your data.






share|improve this answer























  • I fixed that thanks :D
    – Alexandre
    Nov 19 at 17:32










  • Did all worked fine ?
    – Gastón Saillén
    Nov 19 at 17:42










  • Yes thank you :D
    – Alexandre
    Nov 23 at 9:14










  • If that worked can you mark the answer as correct ? Thanks and have a nice weekend
    – Gastón Saillén
    Nov 23 at 10:02















up vote
0
down vote













You have a typo here



item.put("Longitude ", lon);


change it to this



item.put("Longitude", lon);


as that is pushing the key value with " " at your Firebase structure and thats why you can't fetch that value, since a Map needs a Key - Value pair to work and it can't find out the Longitude data.



Also, after changing this, you will need to push new values and delete the ones at your database that are wrong



The logcat exception is pointing out right here



double longitude = Double.parseDouble(map.get("Longitude"));


with this




java.util.Map has generic type parameters




enter image description here



Now , fetching the data.



As I understand, you need to press a button and fetch all LatLang from that node at firebase, let say you have the button Poubelle that gets all the latitude and longitude from that node, that can be done in this way.



        mDatabase = FirebaseDatabase.getInstance().getReference();
DatabaseReference mPoubelleRef = mDatabase.child("Pins").child("Poubelle");

BtnPoubelle.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

mPoubelleRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for(DataSnapshot snapshot: dataSnapshot.getChildren()){
Map<String, String> map = snapshot.getValue(Map.class);
double latitude = Double.parseDouble(map.get("Latitude"));
double longitude = Double.parseDouble(map.get("Longitude"));

//or get the data with a model (is the same thing as above)
YourModel model = snapshot.getValue(YourModel.class);
double latitude = model.getLatitude();
double longitude = model.getLongitude();

}
}

@Override
public void onCancelled(DatabaseError databaseError) {
System.out.println("The read failed: " + databaseError.getCode());
}
});
}


Before retrieving the data, first delete the nodes with




"Longitude " :




or it will fail each time when it tries to get your data.






share|improve this answer























  • I fixed that thanks :D
    – Alexandre
    Nov 19 at 17:32










  • Did all worked fine ?
    – Gastón Saillén
    Nov 19 at 17:42










  • Yes thank you :D
    – Alexandre
    Nov 23 at 9:14










  • If that worked can you mark the answer as correct ? Thanks and have a nice weekend
    – Gastón Saillén
    Nov 23 at 10:02













up vote
0
down vote










up vote
0
down vote









You have a typo here



item.put("Longitude ", lon);


change it to this



item.put("Longitude", lon);


as that is pushing the key value with " " at your Firebase structure and thats why you can't fetch that value, since a Map needs a Key - Value pair to work and it can't find out the Longitude data.



Also, after changing this, you will need to push new values and delete the ones at your database that are wrong



The logcat exception is pointing out right here



double longitude = Double.parseDouble(map.get("Longitude"));


with this




java.util.Map has generic type parameters




enter image description here



Now , fetching the data.



As I understand, you need to press a button and fetch all LatLang from that node at firebase, let say you have the button Poubelle that gets all the latitude and longitude from that node, that can be done in this way.



        mDatabase = FirebaseDatabase.getInstance().getReference();
DatabaseReference mPoubelleRef = mDatabase.child("Pins").child("Poubelle");

BtnPoubelle.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

mPoubelleRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for(DataSnapshot snapshot: dataSnapshot.getChildren()){
Map<String, String> map = snapshot.getValue(Map.class);
double latitude = Double.parseDouble(map.get("Latitude"));
double longitude = Double.parseDouble(map.get("Longitude"));

//or get the data with a model (is the same thing as above)
YourModel model = snapshot.getValue(YourModel.class);
double latitude = model.getLatitude();
double longitude = model.getLongitude();

}
}

@Override
public void onCancelled(DatabaseError databaseError) {
System.out.println("The read failed: " + databaseError.getCode());
}
});
}


Before retrieving the data, first delete the nodes with




"Longitude " :




or it will fail each time when it tries to get your data.






share|improve this answer














You have a typo here



item.put("Longitude ", lon);


change it to this



item.put("Longitude", lon);


as that is pushing the key value with " " at your Firebase structure and thats why you can't fetch that value, since a Map needs a Key - Value pair to work and it can't find out the Longitude data.



Also, after changing this, you will need to push new values and delete the ones at your database that are wrong



The logcat exception is pointing out right here



double longitude = Double.parseDouble(map.get("Longitude"));


with this




java.util.Map has generic type parameters




enter image description here



Now , fetching the data.



As I understand, you need to press a button and fetch all LatLang from that node at firebase, let say you have the button Poubelle that gets all the latitude and longitude from that node, that can be done in this way.



        mDatabase = FirebaseDatabase.getInstance().getReference();
DatabaseReference mPoubelleRef = mDatabase.child("Pins").child("Poubelle");

BtnPoubelle.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

mPoubelleRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for(DataSnapshot snapshot: dataSnapshot.getChildren()){
Map<String, String> map = snapshot.getValue(Map.class);
double latitude = Double.parseDouble(map.get("Latitude"));
double longitude = Double.parseDouble(map.get("Longitude"));

//or get the data with a model (is the same thing as above)
YourModel model = snapshot.getValue(YourModel.class);
double latitude = model.getLatitude();
double longitude = model.getLongitude();

}
}

@Override
public void onCancelled(DatabaseError databaseError) {
System.out.println("The read failed: " + databaseError.getCode());
}
});
}


Before retrieving the data, first delete the nodes with




"Longitude " :




or it will fail each time when it tries to get your data.







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 19 at 15:51

























answered Nov 19 at 15:33









Gastón Saillén

3,0013830




3,0013830












  • I fixed that thanks :D
    – Alexandre
    Nov 19 at 17:32










  • Did all worked fine ?
    – Gastón Saillén
    Nov 19 at 17:42










  • Yes thank you :D
    – Alexandre
    Nov 23 at 9:14










  • If that worked can you mark the answer as correct ? Thanks and have a nice weekend
    – Gastón Saillén
    Nov 23 at 10:02


















  • I fixed that thanks :D
    – Alexandre
    Nov 19 at 17:32










  • Did all worked fine ?
    – Gastón Saillén
    Nov 19 at 17:42










  • Yes thank you :D
    – Alexandre
    Nov 23 at 9:14










  • If that worked can you mark the answer as correct ? Thanks and have a nice weekend
    – Gastón Saillén
    Nov 23 at 10:02
















I fixed that thanks :D
– Alexandre
Nov 19 at 17:32




I fixed that thanks :D
– Alexandre
Nov 19 at 17:32












Did all worked fine ?
– Gastón Saillén
Nov 19 at 17:42




Did all worked fine ?
– Gastón Saillén
Nov 19 at 17:42












Yes thank you :D
– Alexandre
Nov 23 at 9:14




Yes thank you :D
– Alexandre
Nov 23 at 9:14












If that worked can you mark the answer as correct ? Thanks and have a nice weekend
– Gastón Saillén
Nov 23 at 10:02




If that worked can you mark the answer as correct ? Thanks and have a nice weekend
– Gastón Saillén
Nov 23 at 10:02


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53376502%2fi-cant-get-specific-data-from-firebase-java%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Create new schema in PostgreSQL using DBeaver

Deepest pit of an array with Javascript: test on Codility

Costa Masnaga