Flutter Location 服务无响应

Flutter Location service no response

我正在使用 gMaps 开发一个应用程序,在我的应用程序中,我获得了用户的位置许可,之后我请求用户打开 his/her gps。问题是第一次打开gps时,应用程序无法获取位置数据。

这是我的程序卡住的地方:

_locationData = await location.getLocation();
    print(_locationData.latitude);

调用此行后,logcat 中没有消息。我想我无法从提供商处获取位置数据。

void getPermissions() async {
    Location location = new Location();

    bool _serviceEnabled;
    PermissionStatus _permissionGranted;

    _permissionGranted = await location.hasPermission();
    if (_permissionGranted == PermissionStatus.denied) {
      _permissionGranted = await location.requestPermission();
      if (_permissionGranted != PermissionStatus.granted) {
        print('whats happening!');
        return;
      }
    }

    _serviceEnabled = await location.serviceEnabled();
    if (!_serviceEnabled) {
      _serviceEnabled = await location.requestService();
      print('hahahahahahahahahahahahahah' + _serviceEnabled.toString());
      if (!_serviceEnabled) {
        return;
      }
    }

    _locationData = await location.getLocation();
    print(_locationData.latitude);
   
    controller.animateCamera(CameraUpdate.newLatLng(
        new LatLng(_locationData.latitude, _locationData.longitude)));

}
   serviceEnabled = await Geolocator.isLocationServiceEnabled();
    if (!serviceEnabled) {
      Location loc = Location();
      serviceEnabled = await loc.requestService();

      if (!serviceEnabled) {
        return Future.error('Location services are disabled.');
      }
    }

地理定位器:^7.7.1