【发布时间】:2018-02-19 06:30:55
【问题描述】:
我正在使用本机 Google 地图和 Firebase 构建一个 Ionic 应用程序。我想在地图上加载多个标记,这些标记的位置(纬度和经度)在这个 Firebase 结构中:
所以我创建了一个提供者和一个函数getPins() 来获得这些职位:
import { ... };
@Injectable()
public arredoresRef:firebase.database.Reference;
export class ArredoresProvider {
constructor() {
this.arredoresRef = firebase.database().ref('/local')
}
getPins(): firebase.database.Reference {
return this.arredoresRef.child('/local');
}
}
我正在尝试将这些位置放在一个数组中:
import { ... };
@IonicPage({ ... })
@Component({ ... })
export class ArredoresPage {
constructor( ... ) { ... }
ionViewDidEnter() {
this.arredoresProvider.getPins().on('value', snapshot => {
this.pins = [];
snapshot.forEach( snap => {
this.pins.push({
latitude: snap.val().latitudeLocal,
longitude: snap.val().longitudeLocal
});
return false
});
});
}
}
但它不起作用!这是我第一次使用 Firebase 和 Ionic,所以我对 Firebase 如何读取数据感到困惑。
This text 对我非常有用,但它不使用 Firebase 数据。
最后,我为我糟糕的英语道歉!
【问题讨论】:
-
这是什么不工作?您根本不检索针脚吗?您只是无法将它们放入地图中吗?
-
什么不起作用?出租车,你得到了大头针,只是没有把它们放在地图上?
-
我的函数没有检索数据,数组为空。
标签: javascript android firebase ionic-framework firebase-realtime-database