我正在構建一個類似于 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 個是正確的,而且我認為擴展效率不高,因為它增加了我的讀取量和開銷在客戶端過濾它們。
現在我的問題是,如何實作完美的地理查詢來過濾云 Firestore 中最近的餐館和司機?請幫忙。
uj5u.com熱心網友回復:
Firestore 的大多數 geoquery 實作(如
要將回傳的專案限制為您想要的圓形半徑,您需要在執行時對結果進行后處理。在我的測驗中,查詢讀取的檔案比所需的檔案多 5 倍,有些查詢(通常是結果更少的查詢)讀取的檔案多 15 倍。基于此,您的結果似乎是平均水平。
如果您有興趣了解更多資訊,我建議您查看我幾年前所做的演講視頻:根據地理位置或距離查詢 Firebase 和 Firestore。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/349404.html
標籤:火力基地 扑 搜索 谷歌云firestore 地理哈希
下一篇:從Firebase檢索資訊
