如何使用 React Native Cli 在应用程序中实现 geofirestore?

问题描述 投票:0回答:1

我正在尝试使用

geofirestore
从集合文档中获取与
react native Cli
应用程序中的用户位置有一定距离的文档,当尝试实现 geofirestore 时,我收到以下 TypeError:

错误: _$$_REQUIRE(_dependencyMap[9 ], "(...)estore").GeoFirestore.collection 不是一个函数(未定义),你能帮我解决这个问题吗

注意:firestore 的实现是正确的,因为我有其他方法可以正确获取 firestore 集合中的文档,我只在 geofirestore 的实现中收到错误

这些是项目中安装的版本

"firebase": "^9.23.0",
"geofirestore": "^5.2.0",

这是我的firebase配置文件

import { initializeApp } from 'firebase/app';
import { getAuth } from 'firebase/auth';
import { getFirestore } from 'firebase/firestore';

import { GeoFirestore } from 'geofirestore';

const firebaseConfig = {
  apiKey: "",
  authDomain: "",
  databaseURL: "",
  projectId: "",
  storageBucket: "",
  messagingSenderId: "",
  appId: "",
  measurementId: ""
};


const app = initializeApp(firebaseConfig);
const authentication = getAuth(app);
const db = getFirestore(app);

const geofirestore = new GeoFirestore(db);

export { app, authentication, db,  geofirestore };

这是我实现 geofirestore 的文件

import { useNavigation } from "@react-navigation/native";
import { useEffect, useState } from "react";
import GetLocation from 'react-native-get-location'
import { collection, onSnapshot, orderBy, query, where, getDocs } from "firebase/firestore";
import { db } from "../../utils/keys"
import { getAuth } from "firebase/auth";

import { GeoFirestore } from 'geofirestore';

const obtenerRegistrosCercanos = async () => {
   
    const eventosCollection = GeoFirestore.collection(db,'eventos');
    
    const center = new firestore.GeoPoint(19.325471, -99.656188);

    const radius = 10;

    const query = eventosCollection.near({
        center,
        radius,
      });

      query.get().then((snapshot) => {
        snapshot.docs.forEach((doc) => {
          const data = doc.data();
          console.log(data);
        });
      });     
  };
javascript firebase react-native google-cloud-firestore geofirestore
1个回答
0
投票

你成功了吗? 我也有同样的问题

© www.soinside.com 2019 - 2024. All rights reserved.