技术:地理消防局,消防队,角版7
链接到geofirestore:https://github.com/geofirestore/geofirestore-js
当前:
我用的是极限,一次增加20。
问题:
这还不够好,因为它每次都会调用更大的有效载荷,然后随着列表的升序而重新排序,所以它对用户来说真的很混乱。
请让我知道有什么替代分页地火吗?
当前尝试:
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 };
}问题:
发布于 2020-09-13 12:59:08
若要从中心位置检索项目列表,指定半径限制在一定数量的项。
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 queryhttps://stackoverflow.com/questions/54673938
复制相似问题