Flutter 使用地理定位时如何在颤振中自动打开gps

Flutter 使用地理定位时如何在颤振中自动打开gps,flutter,permissions,gps,location,Flutter,Permissions,Gps,Location,我正在尝试使用地理定位软件包获取我的当前位置,但在弹出对话框显示请求我的位置许可后,我单击允许。。。我的gps仍然关闭,我必须手动打开它,有什么我应该添加到我的代码 Position _mine; _myPosition() { final Geolocator geolocator = Geolocator()..forceAndroidLocationManager; geolocator .getCurrentPosition(desiredAccu

我正在尝试使用地理定位软件包获取我的当前位置,但在弹出对话框显示请求我的位置许可后,我单击允许。。。我的gps仍然关闭,我必须手动打开它,有什么我应该添加到我的代码

Position _mine;
   _myPosition() {
    final Geolocator geolocator = Geolocator()..forceAndroidLocationManager;

    geolocator
        .getCurrentPosition(desiredAccuracy: LocationAccuracy.high)
        .then((Position position) {
      setState(() {
        _mine = position;
      });
      print(_mine.latitude);
    }).catchError((err) {

    });
  }
试试这个

  Position currentLocation;
  LatLng _latLng;
  Future<Position> locateUser() async {
  return Geolocator()
      .getCurrentPosition(desiredAccuracy: LocationAccuracy.high);
  }
  getUserLocation() async {
      currentLocation = await locateUser();
      _latLng = LatLng(currentLocation.latitude, currentLocation.longitude);
  }
  LatLng getLatLng(){
      return _latLng;
  }
  updateLatLng(){
      getUserLocation();
  }
位置当前位置;
LatLng _LatLng;
Future locateUser()异步{
返回地理定位器()
.getCurrentPosition(所需精度:定位精度高);
}
getUserLocation()异步{
currentLocation=等待locateUser();
_latLng=latLng(当前位置.纬度,当前位置.经度);
}
LatLng getLatLng(){
返回_latLng;
}
更新{
getUserLocation();
}
试试这个

  Position currentLocation;
  LatLng _latLng;
  Future<Position> locateUser() async {
  return Geolocator()
      .getCurrentPosition(desiredAccuracy: LocationAccuracy.high);
  }
  getUserLocation() async {
      currentLocation = await locateUser();
      _latLng = LatLng(currentLocation.latitude, currentLocation.longitude);
  }
  LatLng getLatLng(){
      return _latLng;
  }
  updateLatLng(){
      getUserLocation();
  }
位置当前位置;
LatLng _LatLng;
Future locateUser()异步{
返回地理定位器()
.getCurrentPosition(所需精度:定位精度高);
}
getUserLocation()异步{
currentLocation=等待locateUser();
_latLng=latLng(当前位置.纬度,当前位置.经度);
}
LatLng getLatLng(){
返回_latLng;
}
更新{
getUserLocation();
}

如果您想强制打开您的设备GPS,您可以使用软件包并使用
'ACTION\u LOCATION\u SOURCE\u SETTINGS'
作为设置名称

如果您想强制打开您的设备GPS,您可以使用软件包并使用
'ACTION\u LOCATION\u SOURCE\u SETTINGS'
作为设置名称

我看不出您的代码中有问题除非您没有在AndroidManifest.xml中设置权限,否则我无法在代码中看到问题,除非您没有在AndroidManifest.xml中设置权限