我想问一个关于Firebase和Geofire的问题。我正在使用Firebase 9.17.1版和Geofire 6.0.0版。根据文档,我已经编写了基本代码,但收到以下错误消息:
[类型错误: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()
函数,数据会被下载,并且不会抛出错误。但是,我不想取消它,因为我需要on函数继续监听。
先谢谢你
1条答案
按热度按时间vngu2lb81#
我也收到了一个错误:"类型错误:子路径对象拆分不是路径子节点(c:\工作\完整性\项目节点\地理监测应用\节点模块@firebase\数据库\分布\索引. esm2017. js:2961:42)处的函数"
https://github.com/firebase/geofire-js/issues/260