簡體   English   中英

Flutter定位服務無響應

[英]Flutter Location service no response

我正在使用 gMaps 開發一個應用程序,在我的應用程序中我獲得了用戶的位置許可,之后我請求用戶打開他/她的 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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM