2

I would like to ask a question regarding Firebase and Geofire. I am using Firebase version 9.17.1 with Geofire version 6.0.0. Based on the documentation, I have written the basic code, but I am receiving the following error message:

[TypeError: t.split is not a function. (In 't.split("/")', 't.split' is undefined)]

. Although the query is working and the ".on" functions are being executed, I am still receiving this error message. Below is the code I am using:

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()});
}

The error is caused by the geoFire.query() function, because if I comment it out, I don't receive an error message. The rest of the code works correctly. If I call the geoQuery.cancel() function, the data is downloaded and no error is thrown. However, I don't want to cancel it because I need the on functions to continue listening.

Thank you in advance

1 Answers1

2

I received an error, too: "TypeError: childPathObj.split is not a function at pathChild (c:\work\integrity\projects-node\GeoMonitoringApp\node_modules@firebase\database\dist\index.esm2017.js:2961:42)"

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

Papp Zoltán
  • 131
  • 7