【问题标题】:How to add or save from web form (Javascript) entry as GeoPoint type in Firebase Firestore如何在 Firebase Firestore 中将 Web 表单(Javascript)条目添加或保存为 GeoPoint 类型
【发布时间】:2020-05-30 05:10:10
【问题描述】:

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

-咖啡馆名称 -纬度 - 其位置的经度。

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

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

我尝试了以下所有方法,但都不起作用。

   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)

【问题讨论】:

    标签: javascript firebase google-maps-api-3 google-cloud-firestore


    【解决方案1】:

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

    let coords = []
    coords.push(new firebase.firestore.GeoPoint(form.lat.value, form.long.value))
    

    【讨论】:

    • 嗨 baby.amas,感谢您的建议,我会去尝试一下并回复您。只是为了检查您的上述代码是否适用于javascript?我尝试查看参考文档以获取答案,但找不到。 firebase.google.com/docs/reference/js/…
    • @lonelearner 你是对的。这是我在我的一个项目中所做的事情,但我节省了很多分。新的 firebase.firestore.GeoPoint(form.lat.value, form.long.value) 应该可以工作。你检查你是否通过了正确的纬度和经度?
    【解决方案2】:

    您缺少对 Firebase 应用的正确引用 请看Vue.js Firestore save geopoint

    您缺少的一点是您必须导入的 firebase 导入

    import { firebase } from '@firebase/app';
    

    你使用的语法是正确的

    coordinates: new firebase.firestore.GeoPoint(form.lat.value, form.long.value)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-11-15
      • 2022-11-22
      • 1970-01-01
      • 2021-08-06
      • 2022-11-30
      • 1970-01-01
      • 2019-05-16
      相关资源
      最近更新 更多