【问题标题】:firebase.firestore.GeoPoint(long, lat) is not a constructorfirebase.firestore.GeoPoint(long, lat) 不是构造函数
【发布时间】:2019-03-17 01:36:13
【问题描述】:

我需要你的帮助...

我无法将带有地理数据的对象保存到我的 Firestore(来自 vue 应用程序)。

没有地理点的对象被保存到 Firestore,但是当我尝试使用 GeoPoint 类添加文档时,我收到以下错误:

Uncaught TypeError: this.$db.GeoPoint is not a constructor
at VueComponent.addProperty (index.2ad219460d4ddfd5635c.hot-update.js:226)
at click (index.3901b064c6620cd7292b.hot-update.js:149)
at invoker (commons.app.js:10574)
at HTMLButtonElement.fn._withTask.fn._withTask [...]

'This.$db' 是对 firebase.firestore() 对象的引用 -> 因为它可以在没有 GeoPoints 的情况下工作,所以这个导入/注入应该是正确的(我也尝试过直接导入 firebase-instance,但没有成功.

我的函数如下所示:

this.$db.collection("property").add({
 meta_data:this.meta_data,
 address: this.address,
  location: new this.$db.GeoPoint(8.241, 46.838)
})
  .then(function(docRef) {
    console.log("Document written with ID: ", docRef.id);
  })
  .catch(function(error) {
    console.error("Error adding document: ", error);
  });

我的依赖:

"dependencies": {
"@mapbox/mapbox-gl-geocoder": "^2.3.0",
"@mapbox/mapbox-sdk": "^0.4.1",
"firebase": "^5.5.3",
"geojson": "^0.5.0",
"gsap": "^2.0.2",
"mapbox-gl": "^0.49.0",
"nuxt": "^2.1.0",
"vuefire": "^1.4.5",
"vuetify": "^1.2.9"
},

我错过了什么吗?任何帮助表示赞赏!非常感谢

【问题讨论】:

    标签: firebase vue.js google-cloud-firestore nuxt.js


    【解决方案1】:

    我找到了问题的根本原因。 This.$db 是对 firebase.firestore() 的引用,而不是对 firebase.firestore -> 因此构造函数不可用。

    【讨论】:

      【解决方案2】:

      我有一个不太好的解决方案。我记得 firebase 模块并使用原始功能。就在我自己的组件中。

      <script>
      import firebase from 'firebase/app'
      import 'firebase/storage'
      
      export default {
          beforeMount() {
              const geopoint = firebase.firestore
              console.log(new geopoint.GeoPoint(-0.180653, -78.467834))
          },
      }
      </script>
      

      【讨论】:

        【解决方案3】:

        我在我的 vue 应用程序中遇到了同样的错误,我在创建地理点时引用了外部 firebase 文件,我的解决方案是添加: import { firebase } from '@firebase/app';

        【讨论】:

          猜你喜欢
          • 2021-03-04
          • 2015-09-28
          • 2013-12-25
          • 2021-01-11
          • 2015-12-04
          • 2018-11-29
          • 2016-12-04
          • 2020-12-27
          • 2021-04-05
          相关资源
          最近更新 更多