2

技术:geofirestore,firestore,角度版本 7

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

目前:

我正在使用限制并一次增加 20 个。

问题:

它还不够好,因为它每次都会调用更大的有效负载,然后随着列表的递增顺序再次对它们进行排序,所以它真的让用户感到困惑。

请让我知道分页geofire的任何替代方法?

当前尝试:

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 等?

4

1 回答 1

0

从中心位置检索项目列表,给定半径限制为一定数量的项目。

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

于 2020-09-13T12:59:08.027 回答