我正在构建一个像 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 = …
Run Code Online (Sandbox Code Playgroud)