如何从输入到FireStore的数据向地图添加自定义标记

时间:2019-04-29 05:25:34

标签: java android firebase google-cloud-firestore

我有一个应用程序,允许我向FireStore提交包含餐厅信息的便笺,此数据保存在名为“便笺”的集合中,并包含“餐厅名称”,“纬度”和“经度”等字段。我希望从FireStore查询此信息,然后使用纬度和经度填充地图,并使用提交的信息说明名称。

我包括了注释类和createNewNote方法。

纬度和经度作为字符串输入,会引起问题吗?

我不确定如何读取纬度和经度,尤其是将其转换为地图上的标记。

感谢您的帮助。

@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);
}

}

0 个答案:

没有答案