【发布时间】:2020-04-15 13:35:47
【问题描述】:
当用户在我确定的位置半径 x 米的范围内时,我目前正在尝试授予用户执行某些操作的权限。所以,我的意思是..我声明了一个 x 纬度和 y 经度的位置.. 然后如果用户的位置距离我声明的位置 500 米,他们可以访问其他东西......有没有办法做到这一点?这是我的代码的一部分
Position _mine;
Future _searchMe() async {
if ((await Geolocator().isLocationServiceEnabled())) {
final Geolocator geolocator = Geolocator()..forceAndroidLocationManager;
geolocator
.getCurrentPosition(desiredAccuracy: LocationAccuracy.high)
.then((Position position) {
setState(() {
_mine = position;
});
print(_mine.latitude);
}).catchError((err) {
print(err);
});
} else {
print("ok");
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
content:
const Text('Make sure your GPS is on !'),
actions: <Widget>[
FlatButton(
child: Text('ok'),
onPressed: () {
Navigator.of(context, rootNavigator: true).pop();
})
],
);
});
}
}
【问题讨论】:
-
你能澄清你的问题吗
-
Geolocator 包提供了一个 distanceBetween 方法。您可以将您确定位置的经度和设备当前位置的经度传递给它,它将返回两点之间的距离(以米为单位)。见:pub.dev/packages/geolocator#calculate-distance
-
您觉得 Distance().as() 有帮助吗?
-
嗨对不起,我忘记投票了
标签: flutter location maps position