Asynchronous 如何在获得用户位置许可后激活GPS
我想在用户打开应用程序时自动启用GPS定位,在用户安装应用程序时授予用户定位权限。如何在颤振中自动激活位置Asynchronous 如何在获得用户位置许可后激活GPS,asynchronous,flutter,dart,gps,location,Asynchronous,Flutter,Dart,Gps,Location,我想在用户打开应用程序时自动启用GPS定位,在用户安装应用程序时授予用户定位权限。如何在颤振中自动激活位置 Geolocator geolocator = Geolocator()..forceAndroidLocationManager; Future<Position> getCurrentLocation() async { Position position = await geolocator.getCurrentPosition( desiredA
Geolocator geolocator = Geolocator()..forceAndroidLocationManager;
Future<Position> getCurrentLocation() async {
Position position = await geolocator.getCurrentPosition(
desiredAccuracy: LocationAccuracy.high);
return position;
}
Geolocator-Geolocator=Geolocator()…forceAndroidLocationManager;
Future getCurrentLocation()异步{
位置=等待地理定位器。getCurrentPosition(
所需精度:定位精度高);
返回位置;
}
使用pub.dev中的lib可以找到所需的解决方案。使用您的代码获得用户的位置权限后,只需添加两行即可。这里还有一个示例代码
import 'package:location/location.dart' as loc;
Future<Position> getCurrentLocation() async {
loc.Location locationR = loc.Location();
if (!await locationR.serviceEnabled()) {
locationR.requestService();
}
Position position = await geolocator.getCurrentPosition(
desiredAccuracy: LocationAccuracy.high);
return position;
}
导入“包:位置/位置.省道”作为loc;
Future getCurrentLocation()异步{
loc.Location locationR=loc.Location();
如果(!wait locationR.servicenabled()){
locationR.requestService();
}
位置=等待地理定位器。getCurrentPosition(
所需精度:定位精度高);
返回位置;
}
这两行代码检查您的GPS是否打开/关闭。如果关闭,则会显示一个打开GPS的提示对话框。与我们分享您尝试自动激活GPS的代码。