在 Firebase 9.17.1 中使用 GeoFire 时出现类型错误:“t.split 不是函数”

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

我想问一个关于 Firebase 和 Geofire 的问题。 我正在使用 Firebase 版本 9.17.1 和 Geofire 版本 6.0.0。 根据文档, 我已经编写了基本代码,但收到以下错误消息:

[TypeError: t.split 不是函数。 (在't.split(“/”)','t.split' 未定义)]

.尽管

query
正在运行并且正在执行“
.on
”功能,但我仍然收到此错误消息。以下是我正在使用的代码:

class DatabaseHelper {
  private database;
  private firebaseRef: DatabaseReference;
  private app;

  constructor(){
    this.database = firebase.app().database('censored');

    this.app = initializeApp({
      apiKey: 'censored',
      appId: 'censored',
      databaseURL: 'censored',
      storageBucket: 'censored'
    });
    this.firebaseRef = ref(getDatabase(this.app));
  }

  public async addDataToGeofire(){
    const geoFire = await new GeoFire(this.firebaseRef);
    const requestId = "-NP4heZ1yLXk96HiScqH";
    const latitude = 45.502686;
    const longitude = 15.0655181;

    await geoFire.set(requestId, [latitude, longitude])
    .then(() => {
      console.log(`Coordinates successfully added to the key: ${requestId}`);
    })
    .catch((error) => {
      console.error(`An error occurred while adding the coordinate" ${error}`);
    });
  }

  public async getDataFromGeofire(){
    const geoFire = await new GeoFire(this.firebaseRef);

    await geoFire.get("-NP4heZ1yLXk96HiScqH").then(function(location) {
      if (location === null) {
        console.log("Provided key is not in GeoFire");
      }
      else {
        console.log("Provided key has a location of " + location);
      }
    }, function(error) {
      console.log("Error: " + error);
    });

    const geoQuery = geoFire.query({
      center: [47, 19],
      radius: 1000
    });

    const onReadyRegistration = geoQuery.on("ready", () => {
      console.log("GeoQuery has loaded and fired all other events for initial data");
    });

   
    // geoQuery.cancel(); <--if I call this function I don't get an error, but I don't think this is the solution.
  }
}

App.tsx:

 constructor(){
  this.someMethod();    
}

async someMethod(){
  await databaseHelper.addDataToGeofire().then(async () => {await databaseHelper.getDataFromGeofire()});
}

错误是由

geoFire.query()
函数引起的,因为如果我注释掉它,我不会收到错误消息。其余代码工作正常。如果我调用
geoQuery.cancel()
函数,数据将被下载并且不会抛出任何错误。但是,我不想取消它,因为我需要打开功能才能继续收听。

提前谢谢你

javascript typescript firebase firebase-realtime-database geofire
1个回答
0
投票

我也收到一个错误:“TypeError: childPathObj.split 不是 pathChild (c:\work\integrity\projects-node\GeoMonitoringApp ode_modules@firebase\database\dist\index.esm2017.js:2961:42)"

https://github.com/firebase/geofire-js/issues/260

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