问题
Hi i have a web form which collect the following:
-cafe name -latitude -longitude of its location.
Currently, the lat and long is saved as map format instead of GeoPoint in Firestore. Hence i would like to seek your advice on how it could be saved as GeoPoint format/data type.
form.addEventListener('submit',(e)=>{
e.preventDefault();
db.collection('sgcafe').add ({
name: form.name.value,
category: form.category.value,
coordinates: {Latitude:form.lat.value,Longtitude:form.long.value} //save as map not Geopoint
I tried all the following but it does not works.
coordinates: new firebase.firestore.GeoPoint(form.lat.value, form.long.value)
coordinates: firebase.firestore.GeoPoint(form.lat.value, form.long.value)
coordinates: GeoPoint(form.lat.value, form.long.value)
回答1:
If I'm right you need to send an array of coordinates to your firestore database so before the addition try this and then pass the array av value to your object's coordinates key.
let coords = []
coords.push(new firebase.firestore.GeoPoint(form.lat.value, form.long.value))
来源:https://stackoverflow.com/questions/62098100/how-to-add-or-save-from-web-form-javascript-entry-as-geopoint-type-in-firebase