How to add or save from web form (Javascript) entry as GeoPoint type in Firebase Firestore

怎甘沉沦 提交于 2020-07-23 07:07:58

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!