0

I have an application that allows me to submit a note containing restaurant information to FireStore, this data is saved in a collection called "notes" and contains fields such as the "Restaurant Name", "latitude" and "longitude". I wish to query this info from FireStore then populate a map using the latitude and longitude and states the name using the info submitted.

I have included the note class and the createNewNote method.

The latitude and longitude are inputted as strings, would that cause issues?

I’m not sure how to read the latitude and longitude and translate it to a marker on a map in particular.

Thanks for any help.

@Override
public void createNewNote
        (String attractionName, String review,
         String attractionAddress, String cuisine, String latitude, String 
longitude) {

    FirebaseFirestore db = FirebaseFirestore.getInstance();

    String userId = FirebaseAuth.getInstance().getCurrentUser().getUid();

    DocumentReference newNoteRef = db
            .collection("notes")
            .document();

    Note note = new Note();
    note.setAttractionName(attractionName);
    note.setReview(review);
    note.setNote_id(newNoteRef.getId());
    note.setUser_id(userId);
    note.setAttractionAddress(attractionAddress);
    note.setCuisine(cuisine);
    note.setLatitude(latitude);
    note.setLongitude(longitude);


    newNoteRef.set(note).addOnCompleteListener(new 
    OnCompleteListener<Void>() {
        @Override
        public void onComplete(@NonNull Task<Void> task) {
            if(task.isSuccessful()){
                makeSnackBarMessage("Submit new activity");
                getNotes();
            }
            else{
                makeSnackBarMessage("Failed. Check log.");
            }
        }
    });
}


private String attractionName;
private String review;
private @ServerTimestamp
Date timestamp;
private String note_id;
private String user_id;
private String cuisine;
private GeoPoint attractionLocation;
private String attractionAddress;
private String latitude;
private String longitude;



public Note(String attractionName, String review, Date timestamp, String 
note_id, String user_id, String cuisine, String attractionAddress, String 
latitude, String longitude) {
    this.attractionName = attractionName;
    this.review = review;
    this.timestamp = timestamp;
    this.note_id = note_id;
    this.user_id = user_id;

    this.cuisine = cuisine;
    this.attractionAddress = attractionAddress;
    this.latitude = latitude;
    this.longitude = longitude;
 }

 public Note() {

 }

 protected Note(Parcel in) {
    attractionName = in.readString();
    review = in.readString();
    note_id = in.readString();
    user_id = in.readString();
    cuisine = in.readString();
    attractionAddress = in.readString();
    latitude = in.readString();
    longitude = in.readString();
}

public static final Creator<Note> CREATOR = new Creator<Note>() {
    @Override
    public Note createFromParcel(Parcel in) {
        return new Note(in);
    }

    @Override
    public Note[] newArray(int size) {
        return new Note[size];
    }
};

public String getUser_id() {
    return user_id;
}

public void setUser_id(String user_id) {
    this.user_id = user_id;
}

public String getAttractionName() {
    return attractionName;
}

public void setAttractionName(String attractionName) {
    this.attractionName = attractionName;
}

public String getReview() { return review; }

public void setReview(String review) {
    this.review = review;
}

public Date getTimestamp() {
    return timestamp;
}

public void setTimestamp(Date timestamp) {
    this.timestamp = timestamp;
}


public String getCuisine() {
    return this.cuisine;
}

public void setCuisine(String cuisine) {
    this.cuisine = cuisine;
}

public String getNote_id() {
    return note_id;
}

public void setNote_id(String note_id) {
    this.note_id = note_id;
}

public GeoPoint getAttractionLocation() {return attractionLocation; }

public void getAttractionLocation(GeoPoint attractionLocation) {this.attractionLocation = attractionLocation;}

public String getAttractionAddress() {return this.attractionAddress; }

public void setAttractionAddress(String attractionAddress) {this.attractionAddress = attractionAddress;}

public String getLongitude() {return this.longitude; }

public void setLongitude(String longitude) {this.longitude = longitude;}

public String getLatitude() {return this.latitude; }

public void setLatitude(String latitude) {this.latitude = latitude;}




@Override
public int describeContents() {
    return 0;
}

@Override
public void writeToParcel(Parcel parcel, int i) {
    parcel.writeString(attractionName);
    parcel.writeString(review);
    parcel.writeString(note_id);
    parcel.writeString(user_id);
    parcel.writeString(cuisine);
    parcel.writeString(attractionAddress);
    parcel.writeString(latitude);
    parcel.writeString(longitude);
}

}

  • Please add your database structure to see how you store your `Note` objects. – Alex Mamo Apr 29 '19 at 08:06
  • @AlexMamo Do you mean just a screenshot of the database in FireStore console? If so [Link] (https://imgur.com/xrCngx4), if that's not what you need please let me know, thank you! – Andrew Taylor Apr 29 '19 at 08:37

0 Answers0