auf die auf erstelle ich dies tun:Datenbank in Feuerbasis, wie spcific Informationen zu nehmen und zu spcific Marker google map
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
FirebaseDatabase database = FirebaseDatabase.getInstance();
mDatabase = FirebaseDatabase.getInstance().getReference();
ich verwende in google map Marker und wenn der Benutzer einen anderen Ort speichern möchte ich Erfolg haben um den Marker genau den LATLNG des User Picks zu setzen. aber ich habe mehr Informationen, die der Benutzer wie Ortsname, Bewertung, etc ... und ich trage nicht, um die Informationen auf den gleichen Marker setzen, die die Verwendung hinzufügen. hier i hinzufügen Markierung von Firebase Datenbank:
mDatabase.child("Bath").addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
for (DataSnapshot data : dataSnapshot.getChildren());
Bathroom bathroom=dataSnapshot.getValue(Bathroom.class);
double locationSaveLat = bathroom.getLocationBathBLat();
double locationSaveLon = bathroom.getLocationBathALon();
mMap.addMarker(new MarkerOptions().position(new LatLng(locationSaveLon,locationSaveLat)).draggable(false).icon(BitmapDescriptorFactory
.fromResource(R.drawable.bath_small)).title(titleReadFragment));
Log.d("data", bathroom.getRatebath());
}
@Override
public void onChildChanged(DataSnapshot dataSnapshot, String s) {
Log.d("data change",dataSnapshot.toString());
}
@Override
public void onChildRemoved(DataSnapshot dataSnapshot) {
Log.d("data remove",dataSnapshot.toString());
}
@Override
public void onChildMoved(DataSnapshot dataSnapshot, String s) {
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
dies mein Fragment Klasse SaveBathroonFragment wird hier i speichern Details Marker und Push-to-Feuerbasis.
hier kann ich nicht erfolgreich sein, die Informationen zu bestimmten Marker hinzufügen, geben Sie die erste Information für alle Marker und nicht geben Sie mir die spezifischen Informationen für bestimmte Marker. ich denke Notwendigkeit für Schleife aber ich weiß nicht, wie genau das tut.
public class SaveBathroonFragment extends DialogFragment {
private static final String fireBase_URL="https://bathroomfinder.firebaseio.com/path/to/data";
private DatabaseReference databaseReference;
FirebaseStorage storage;
StorageReference mountainsRef;
private Activity context;
private static int RESULT_LOAD_IMAGE = 2;
private ArrayList<Bitmap> bitmapList=new ArrayList<Bitmap>();
View view;
private static Uri selectedImage;
UploadTask uploadTask;
InputStream inputStream;
Bitmap bitmap;
Handler handler;
EditText locationLatitudeEditText;
EditText locationLongitudeEditText;
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
databaseReference = FirebaseDatabase.getInstance().getReference();
storage = FirebaseStorage.getInstance();
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
double locationLON = getArguments().getDouble(MapsActivity.LON);
double locationLAT = getArguments().getDouble(MapsActivity.LAT);
builder.setMessage("Add new bathroom");
view = context.getLayoutInflater().inflate(R.layout.save_bathroom_fragment, null, false);
Button pickPhoto = (Button) view.findViewById(R.id.bpickphoto);
pickPhoto.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
TakePickphoto();
}
});
AdapterImageView adapterImageView = new AdapterImageView(getActivity(), bitmapList);
final EditText bathroomName = (EditText) view.findViewById(R.id.name_bath);
builder.setView(view);
locationLatitudeEditText = (EditText) view.findViewById(R.id.latitude_map);
locationLongitudeEditText = (EditText) view.findViewById(R.id.longitude_map);
locationLatitudeEditText.setText(locationLAT+"");
locationLongitudeEditText.setText(locationLON+"");
locationLongitudeEditText.setEnabled(false);
locationLatitudeEditText.setEnabled(false);
EditText rateBatroomEditText = (EditText) view.findViewById(R.id.rate_batroom);
rateBatroomEditText.setEnabled(false);
bathroomName.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId== EditorInfo.IME_ACTION_SEND){
sendMessage();
}
return true;
}
});
builder.setPositiveButton("Back", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
builder.setNegativeButton("Save", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
sendMessage();
}
});
return builder.create();
}
private void sendMessage() {
EditText nameBathroomSave = (EditText) view.findViewById(R.id.name_bath);
RatingBar rateBatroomSave = (RatingBar) view.findViewById(R.id.ratingBar);
double locationBathBLat = Double.parseDouble(locationLatitudeEditText.getText().toString());
double locationBathALon = Double.parseDouble(locationLongitudeEditText.getText().toString());
String messageBath = nameBathroomSave.getText().toString();
String rathbath = rateBatroomSave.getRating() + "";
if (!messageBath.isEmpty()) {
Random rand = new Random();
String autor = "test" + rand.nextInt(1000);
Bathroom bathroom = new Bathroom(autor, messageBath, rathbath, locationBathALon,locationBathBLat);
if (databaseReference.child("Bath") != null) {
if (databaseReference.child("Bath").child(autor) != null) {
databaseReference.child("Bath").child(autor).setValue(bathroom);
databaseReference.push().getDatabase();
} else {
Toast.makeText(getActivity(), "missing some ", Toast.LENGTH_SHORT).show();
}
hier ist meine Klasse ReadBathroomFragment, was ich in Fragment Klasse speichern und diese Klasse ist auch Fragment
public class ReadBathroomFragment extends DialogFragment {
private Activity context;
GoogleMap mMap;
private static LatLng locationDirectionClickOnMap;
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
final DatabaseReference mDatabase = FirebaseDatabase.getInstance().getReference();
double locationLON = getArguments().getDouble(MapsActivity.LON);
double locationLAT = getArguments().getDouble(MapsActivity.LAT);
locationDirectionClickOnMap = new LatLng(locationLON,locationLAT);
// builder.setTitle("Title");
builder.setTitle("Bathroom details");
//builder.setMessage("Bathroom details");
View view = context.getLayoutInflater().inflate(R.layout.read_bathroom_fragment, null, false);
builder.setView(view);
final EditText placeName= (EditText) view.findViewById(R.id.name_read_bath);
placeName.setEnabled(false);
final EditText rateBatroomEditText = (EditText) view.findViewById(R.id.read_rate_batroom);
rateBatroomEditText.setEnabled(false);
final RatingBar readRating= (RatingBar) view.findViewById(R.id.read_ratingBath);
readRating.setEnabled(true);
EditText locationReadText = (EditText) view.findViewById(R.id.latlng_map_read);
locationReadText.setText(locationLON + "," + locationLAT);
//locationReadText.setText(Locationq);
locationReadText.setEnabled(false);
mDatabase.child("Bath").addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
// for (DataSnapshot data : dataSnapshot.getChildren());
Bathroom bathroom = dataSnapshot.getValue(Bathroom.class);
Log.d("children count", String.valueOf(dataSnapshot.getChildrenCount()));
readRating.setRating(Float.parseFloat(bathroom.getRatebath()));
placeName.setText(bathroom.getMessageNameBath());
}
@Override
public void onChildChanged(DataSnapshot dataSnapshot, String s) {
for (DataSnapshot data : dataSnapshot.getChildren());
Bathroom bathroom=dataSnapshot.getValue(Bathroom.class);
Log.d("children count", String.valueOf(dataSnapshot.getChildrenCount()));
readRating.setRating(Float.parseFloat(bathroom.getRatebath()));
placeName.setText(bathroom.getMessageNameBath());
}
@Override
public void onChildRemoved(DataSnapshot dataSnapshot) {
}
@Override
public void onChildMoved(DataSnapshot dataSnapshot, String s) {
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
builder.setPositiveButton("Back", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
builder.setNegativeButton("Thank you", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
return builder.create();
}
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
this.context = activity;
}
}
hier mein Badezimmer Klasse
public class Bathroom {
private String autor;
private String messageNameBath;
private String ratebath;
private double locationBathBLat;
private double locationBathALon;
public Bathroom() {
}
public double getLocationBathBLat() {
return locationBathBLat;
}
public double getLocationBathALon() {
return locationBathALon;
}
public String getRatebath() {
return ratebath;
}
public Bathroom(String autor, String messageNameBath, String ratebath
,double locationBathBLat,double locationBathALon) {
this.autor = autor;
this.messageNameBath = messageNameBath;
this.ratebath=ratebath;
this.locationBathBLat=locationBathBLat;
this.locationBathALon=locationBathALon;
}
public String getAutor() {
return autor;
}
public String getMessageNameBath() {
return messageNameBath;
}
}
Ich verstehe nicht, was Sie tun möchten. Kannst du deine 'Badezimmer'-Klasse posten? und wie ist deine Firebase-Datenbank für den Badezimmerknoten strukturiert? Es ist besser, wenn Sie mehr Erklärung oder einige Illustrationen geben können :) – Wilik
Ich bearbeite die Post und füge meine Badezimmerklasse hinzu und erstelle sie. Ich möchte spezifische Daten zu scicific Marker erhalten und setzen Sie die genaue Information , um es an den spezifischen Marker anzupassen. Sie wissen, wie Firebase arbeiten? –
also möchten Sie die Bewertung und Autor Informationen in das Info-Fenster wie [this] (http://i.stack.imgur.com/9fViO.png) setzen? und können Sie Ihre Firebase-Datenbankstruktur posten? – Wilik