Vue.js Firestore保存地理位置 [英] Vue.js Firestore save geopoint

查看:32
本文介绍了Vue.js Firestore保存地理位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有!我对Vue.js和 JavaScript 完全陌生.我正在遵循一些youtube指南来了解其工作原理,但是当我无法将 GeoPoint 添加到我的Firestore数据库中时,我就遇到了问题.

there! I am very new to Vue.js and JavaScript at all. I am following some youtube guide to understand how it works, but I've faced with the problem when I can't add GeoPoint to my Firestore database.

这就是我所拥有的:

firebaseInit.js

import firebase from 'firebase'
import 'firebase-admin'
import firebaseConfig from './firebaseConfig'
import { scrypt } from 'crypto';
const firebaseApp = firebase.initializeApp(firebaseConfig)
export default firebaseApp.firestore()

相关 .vue 文件中的

script :

<script>
import db from "./firebaseInit";
 ...
 greet: function(event) {
  db.collection("events_test").add({
    name: this.name,
    ...
    location: new admin.firestore.GeoPoint(51.435454, 31.445456),
    phone: this.phone
    },
    originalUrl: this.originalUrl,
    createdAt: new Date(),
    updatedAt: new Date()
  })
  .then(docRef =>{
      alert(docRef.id)
  })
  .catch(error => {
       alert(error)
  });
  <script>

新的admin.firestore.GeoPoint(51.435454,31.445456)此初始化对我不起作用.以及 new GeoPoint(lat,lng) firebase.firestore.GeoPoint(lat,lng).我总是得到 ReferenceError ,它没有在 Vue.Component 中定义.请帮忙.

new admin.firestore.GeoPoint(51.435454, 31.445456) this initialization doesn't work for me. As well as new GeoPoint(lat,lng) and firebase.firestore.GeoPoint(lat,lng). I always get ReferenceError that it is not defined in Vue.Component. Please help.

推荐答案

通过执行 import'firebase-admin' location:new admin.firestore.GeoPoint(51.435454,31.445456),,您正在尝试在JavaScript/Web应用程序(由Vue.js构建)中使用Admin SDK.

By doing import 'firebase-admin' and location: new admin.firestore.GeoPoint(51.435454, 31.445456), you are trying to use the Admin SDK in a JavaScript/Web application (built with Vue.js).

这不是Admin SDK的目标,即让您在特权环境中与Firebase 进行交互",即通常由您完全控制的服务器.有关更多详细信息,请参阅文档: https://firebase.google.com/docs/admin/setup https://firebase.google.com/docs/reference/admin/

This is not the goal of the Admin SDK which "lets you interact with Firebase from privileged environments", i.e. from a Server that you normally fully control. See the doc for more details: https://firebase.google.com/docs/admin/setup and https://firebase.google.com/docs/reference/admin/

您应使用标准" JavaScript SDK创建GeoPoint(请参见

In your case you should use the "standard" JavaScript SDK to create the GeoPoint (see https://firebase.google.com/docs/reference/js/firebase.firestore.GeoPoint) by doing:

<script>
import firebase from 'firebase/app'
import db from "./firebaseInit";
 ...
 greet: function(event) {
  db.collection("events_test").add({
    name: this.name,
    ...
    location: new firebase.firestore.GeoPoint(51.435454, 31.445456),
    phone: this.phone
    }
  ....

请注意,您需要在组件中导入 firebase/app .

Note that you need to import firebase/app in your component.

请注意,

phone: this.phone
},
originalUrl: this.originalUrl,

这篇关于Vue.js Firestore保存地理位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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