使用Firebase获取用户和Geofire查询密钥需要很长时间
我对GeoFire和RXJS的工作还很陌生 我需要根据Geofire查询显示附近的用户。我尝试了很多方法,但需要很长时间,大约9段(只有5-6个测试用户)。我如何优化它 提前谢谢你的帮助 在火基使用Firebase获取用户和Geofire查询密钥需要很长时间,firebase,rxjs,ionic3,angularfire2,geofire,Firebase,Rxjs,Ionic3,Angularfire2,Geofire,我对GeoFire和RXJS的工作还很陌生 我需要根据Geofire查询显示附近的用户。我尝试了很多方法,但需要很长时间,大约9段(只有5-6个测试用户)。我如何优化它 提前谢谢你的帮助 在火基 -locations - userID - g - l - 0:lat - 1:long - users -userID - firstname: "fname" - lastname... 地球消防局 hits=新行为主体
-locations
- userID
- g
- l
- 0:lat
- 1:long
- users
-userID
- firstname: "fname"
- lastname...
地球消防局
hits=新行为主体([])
people.html
<ion-item *ngFor="let nearby of nearbyUsers$ | async" class="item item-block item-md">
<ion-row>
<ion-col col-3 >...
</ion-col>
<ion-col col-9 (click)="navigateTo('user-profile', nearby.user)">
<ion-row>
<ion-col col-4 >
<span>A {{nearby.distance | roundNumber }} km</span>
</ion-col>
</ion-row>
<ion-row>
<h3> {{nearby.user.firstname}} {{nearby.user["lastname"]}}</h3>
</ion-row>
</ion-col>
</ion-row>
</ion-item>
...
A{{附近距离|轮号}}公里
{{nearest.user.firstname}{{nearest.user[“lastname”]}
浏览器控制台
所以我要说的是,您可能已经做了最好的事情。
geofire
更像是一个索引,您可以在Firebase RTDB中获取对实际文档/对象的引用。Firestore有一些库,例如(我的个人宝贝),也允许您根据位置只进行一次查询并获取文档
geofirestore
在引擎盖下的工作方式方面与geofire
更为相似,并且可能更容易过渡到(如果您感兴趣的话)。终于找到了!我在输入每个键后添加firebase调用,并将每个用户数据添加到行为主题。此外,我将getNearLocations移动到应用程序中的默认选项卡(记录后的第一个视图),然后将行为主题值转换为People.ts中的可观察值。就这样!
this.locateActiveUser().then((pos) => {
this.geofire.getNearLocations(2, [pos.coords.latitude, pos.coords.longitud])
this.subscription = this.geofire.hits
.subscribe( nearUserArray => {
Promise.all(
nearUserArray.map(nearUser => {
this.afDatabase.object(`users/${nearUser.key}`).query.once('value')
.then( user => {
nearUser["user"]= user.val(); })
return nearUser
})).then( a => {
console.log("nearUserArray: ", nearUserArray);
this.nearbyUsers$ = of(nearUserArray);
})
})
})
<ion-item *ngFor="let nearby of nearbyUsers$ | async" class="item item-block item-md">
<ion-row>
<ion-col col-3 >...
</ion-col>
<ion-col col-9 (click)="navigateTo('user-profile', nearby.user)">
<ion-row>
<ion-col col-4 >
<span>A {{nearby.distance | roundNumber }} km</span>
</ion-col>
</ion-row>
<ion-row>
<h3> {{nearby.user.firstname}} {{nearby.user["lastname"]}}</h3>
</ion-row>
</ion-col>
</ion-row>
</ion-item>