如何解决地理查询不适用于子集合 - Firestore
我正在尝试使用 Flutter 中的 Geo Queries 检索附近的所有餐馆。这些位置添加在“餐厅”集合下的每个餐厅文档中。我认为子集合可能会导致问题,因为根据 GeoFlutterFire 文档,所有位置都放在一个集合中。有没有办法在子集合中进行这项工作?如果不是,我应该使用什么方法?
_getUserLocation() async {
final location1 = Location();
final geo = Geoflutterfire();
// var collectionReference =
// FirebaseFirestore.instance.collection('restaurants');
// double radius = 50;
// String field = 'position';
_serviceEnabled = await location1.serviceEnabled();
if (!_serviceEnabled) {
_serviceEnabled = await location1.requestService();
if (!_serviceEnabled) {
return;
}
}
_permissionGranted = await location1.hasPermission();
if (_permissionGranted == PermissionStatus.denied) {
_permissionGranted = await location1.requestPermission();
if (_permissionGranted != PermissionStatus.granted) {
return;
}
}
// final location = Location.instance.getLocation();
// await location.then((value) {
// latitude = value.latitude;
// longitude = value.longitude;
// });
GeoFirePoint myLocation =
geo.point(latitude: 6.55526689,longitude: -73.13373892);
await FirebaseFirestore.instance
.collection('users')
.doc('NUdKiZVLblbceWVRjONFQwW5Wg72')
.collection('locations')
.doc('NUdKiZVLblbceWVRjONFQwW5Wg72')
.set({'name': 'Home','position': myLocation.data});
setState(() {
_isLoading = false;
});
GeoFirePoint center =
geo.point(latitude: 7.08594109039762,longitude: 286.95225338731285);
var collectionReference =
FirebaseFirestore.instance.collection('users.locations');
var geoRef = geo.collection(collectionRef: collectionReference);
Stream<List<DocumentSnapshot>> stream = geoRef.within(
center: center,radius: 150,field: 'position',strictMode: true);
stream.listen((List<DocumentSnapshot> documentList) {
print(documentList.length);
});
}
我得到的输出是:
颤动:0
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。