gpt4 book ai didi

firebase - Flutter Firestore Geo 查询距我所在位置一定距离

转载 作者:行者123 更新时间:2023-12-02 16:05:11 25 4
gpt4 key购买 nike

我将我的用户数据(包括他们的实时位置)作为 GeoPoint 数据类型存储在我的 firebase 数据库中。现在我需要从距离我的位置一定距离的数据库中选择并获取用户。我使用这行代码来检索我的位置:

position = await Geolocator.getCurrentPosition(desiredAccuracy: LocationAccuracy.high);

不,我需要一个 flutter 中的 firebase 查询来检索我周围 500 米的用户。这意味着我应该检索距离 firebase 数据库 500 米的所有用户。我该怎么做?

最佳答案

最后我找到了解决方案:

position = await Geolocator.getCurrentPosition(desiredAccuracy: LocationAccuracy.high);
await getGenderIcons(context);
QuerySnapshot querySnapshot;
double lat = 0.0144927536231884;
double lon = 0.0181818181818182;
double distance = 1000*0.000621371;
double lowerLat = position.latitude - (lat * distance);
double lowerLon = position.longitude - (lon * distance);
double greaterLat = position.latitude + (lat * distance);
double greaterLon = position.longitude + (lon * distance);
GeoPoint lesserGeopoint = GeoPoint(lowerLat,lowerLon);
GeoPoint greaterGeopoint = GeoPoint(greaterLat,greaterLon);
querySnapshot = await usersRef
.where("livelocation", isGreaterThan: lesserGeopoint)
.where("livelocation", isLessThan: greaterGeopoint)
.limit(100)
.get();

关于firebase - Flutter Firestore Geo 查询距我所在位置一定距离,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69607259/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com