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

问题描述 投票:0回答:2

我正在尝试使用Geolocator软件包获取当前位置,但是在弹出对话框显示询问我的位置的权限后,我单击允许...。我的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) {

    });
  }
flutter permissions gps location
2个回答
0
投票

尝试一下

  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();
  }

0
投票

如果您想强制打开设备的GPS,则可以使用access_settings_menu程序包,并使用'ACTION_LOCATION_SOURCE_SETTINGS'作为设置名称

© www.soinside.com 2019 - 2024. All rights reserved.