【发布时间】:2021-11-04 12:23:34
【问题描述】:
我正在构建一个像 Uber Eats 一样的订餐应用。所以,我正在使用 Flutter 制作一个应用程序,但是现在我遇到了寻找最近餐厅的问题。
我目前正在使用 geoflutterfire 包存储位置详细信息。请看附图。
看看我的代码。
getLocation() async {
// Create a geoFirePoint
GeoFirePoint center =
geo.point(latitude: 28.706707247639613, longitude: 80.58572410373661);
// get the collection reference or query
var collectionReference = _firestore.collection('locations');
double radius = 5;
String field = 'position';
Stream<List<DocumentSnapshot>> stream = geo
.collection(collectionRef: collectionReference)
.within(center: center, radius: radius, field: field);
stream.forEach((element) {
element.forEach((e) {
double fbLat = e.get('position')['geopoint'].latitude;
double fbLng = e.get('position')['geopoint'].longitude;
LatLng loc2 = LatLng(fbLat, fbLng);
LatLng loc1 = LatLng(center.latitude, center.longitude);
final distance =
distanceBetweenTwoLocations(location1: loc1, location2: loc2);
print('=======distance is ======');
print('${distance / 1000}KM');
});
});
}
是的,我从数据库中返回最近的位置,但是我返回了 30 多个结果,其中只有 6-7 个是正确的,我认为扩展效率不高,因为它增加了我的读取以及在客户端过滤它们的开销。
现在我的问题是,如何实施完美的地理查询来过滤 Cloud Firestore 中最近的餐馆和司机?请帮忙。
【问题讨论】:
标签: firebase flutter search google-cloud-firestore geohashing