首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >我使用geofirestore和防火墙,并希望对结果进行分页

我使用geofirestore和防火墙,并希望对结果进行分页
EN

Stack Overflow用户
提问于 2019-02-13 15:36:43
回答 1查看 1.1K关注 0票数 2

技术:地理消防局,消防队,角版7

链接到geofirestore:https://github.com/geofirestore/geofirestore-js

当前:

我用的是极限,一次增加20。

问题:

这还不够好,因为它每次都会调用更大的有效载荷,然后随着列表的升序而重新排序,所以它对用户来说真的很混乱。

请让我知道有什么替代分页地火吗?

当前尝试:

代码语言:javascript
复制
public getResults(geo: any, lastLimit: number) {
  const geocollection: GeoCollectionReference = this.geofirestore.collection('test');
  const query = geocollection.near({ center: new firebase.firestore.GeoPoint(geo.lat, geo.lng), radius: geo.radius });
  lastLimit = lastLimit + 2;

  return query.limit(lastLimit).get().then((querySnapshot) => {
    return this.mapResponse(querySnapshot, lastLimit);
  });
}


public mapResponse(querySnapshot: GeoQuerySnapshot, lastLimit: number): any {
   let jobs = [];

   querySnapshot.forEach((doc) => {
    jobs = [ ...jobs, doc.data() ];
 });

 return { jobs, lastLimit };
}

问题:

  1. 如果没有分页,什么时候可以分页?
  2. 如果现在没有,我该怎么处理呢?
  3. 如果它是可用的,我如何做到这一点,通常我使用startAt / startAfter等?
EN

回答 1

Stack Overflow用户

发布于 2020-09-13 12:59:08

若要从中心位置检索项目列表,指定半径限制在一定数量的项。

代码语言:javascript
复制
val db = FirebaseFirestore.getInstance()

/*Create two object to pass location and distance for radius*/
val centerLocation = Location(centerLatitude, centerLongitude)
val distanceForRadius = Distance(1.0, DistanceUnit.KILOMETERS) // or you can set unit as DistanceUnit.MILES if you want to find for 1 mile

val geoQuery = GeoQuery()
        .collection("users")
        .whereEqualTo("status","approved")
        .whereEqualTo("country","IN")
        .whereNearToLocation(centerLocation, distanceForRadius, fieldName) 
        //fieldName if you have passed at time of setLocation else it will take default as "g" if you do not pass
        .startAfter(lastDocument) //optinal (for pagination)
        .limit(10) // If you requires only 10 data per query

参考https://github.com/chintan369/Geo-FireStore-Query

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54673938

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档