最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

flutter - Not able to get position by Geolocator package when I'm offline - Stack Overflow

programmeradmin1浏览0评论

I'm using Geolocator.getCurrentPosition() method:

Future<Position> getCurrentPosition({
LocationSettings? locationSettings,
    LocationAccuracy desiredAccuracy = LocationAccuracy.best,
    bool forceAndroidLocationManager = false,
    Duration? timeLimit,
  }) async {
    LocationSettings? settings;
    if (locationSettings != null) {
      settings = locationSettings;
    } else if (defaultTargetPlatform == TargetPlatform.android) {
      settings = AndroidSettings(
        accuracy: desiredAccuracy,
        forceLocationManager: forceAndroidLocationManager,
      );
    }
    try {
      settings ??= LocationSettings(
        accuracy: desiredAccuracy,
        timeLimit: timeLimit,
      );
      debugPrint("await starts");
      Position position = await Geolocator.getCurrentPosition(
        locationSettings: settings,
      ).then(
        (value) {
          debugPrint("await stop");
          return value;
        },
      );

      return position;
    } catch (e) {
      debugPrint(e.toString());
      return Geolocator.getCurrentPosition(
        locationSettings: settings,
      );
    }
  }

I tried to use other packages as well like Location but still not able to get location when internet is not available.

发布评论

评论列表(0)

  1. 暂无评论