如何在Firebase Firestore中从Web表单(Javascript)条目添加或保存为GeoPoint类型 [英] How to add or save from web form (Javascript) entry as GeoPoint type in Firebase Firestore

查看:80
本文介绍了如何在Firebase Firestore中从Web表单(Javascript)条目添加或保存为GeoPoint类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个收集以下内容的网络表单:

Hi i have a web form which collect the following:

咖啡厅名称 -纬度 -其位置的经度.

-cafe name -latitude -longitude of its location.

当前,纬度和经度已保存为地图格式,而不是Firestore中的GeoPoint.因此,我想就如何将其保存为GeoPoint格式/数据类型征询您的意见.

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)

推荐答案

如果我是对的,您需要将一个坐标数组发送到您的firestore数据库,因此在添加之前尝试此操作,然后将数组av值传递给对象的坐标键.

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))

这篇关于如何在Firebase Firestore中从Web表单(Javascript)条目添加或保存为GeoPoint类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆