Geolocator package 在 Flutter 中不工作。

huangapple go评论72阅读模式
英文:

Geolocator package not working in Flutter

问题

I have worked with the geolocator package before. It seems like your app is having trouble getting the location due to permission issues. You mentioned making changes in the AndroidManifest and info.plist files, but it's still not working. Please provide more details if you need further assistance.

英文:

has any one of you worked with the geolocator package?
if yes then can you please help.
I have done all the steps mentioned in the docs of the geolocator package excluding the androidx conversion
I think the error that I am getting is that the app is not able to get the location. The permission is not being granted I don't know why
Geolocator package 在 Flutter 中不工作。

Geolocator package 在 Flutter 中不工作。

i'm currently testing it on an emulator not a real device.

i have tried making the changes in the android manifest and the info.plist for both ios and android but I don't know why it's not working. One time when I ran the app it said something like the API was outdated or so, but that error did not occur after I rebuild the whole app.
if you know what is wrong and require some other info regarding my code. Please feel free to comment and I'll provide you with the necessary details.

答案1

得分: 1

**

你尝试过这个吗?

**

serviceEnabled = await Geolocator.isLocationServiceEnabled();

if (serviceEnabled) {
  serviceEnabled = true;
} else {
  serviceEnabled = false;
}

LocationPermission _permission = await Geolocator.checkPermission();

if (_permission == LocationPermission.denied) {
  _permission = await Geolocator.requestPermission();
  if (_permission == LocationPermission.always || _permission == LocationPermission.whileInUse) {
    permissionGranted = true;
  } else {
    permissionGranted = false;
  }
} else {
  if (_permission == LocationPermission.always || _permission == LocationPermission.whileInUse) {
    permissionGranted = true;
  } else {
    permissionGranted = false;
  }
}

if (serviceEnabled && permissionGranted) {
  try {
    locationData = await Geolocator.getCurrentPosition(desiredAccuracy: LocationAccuracy.bestForNavigation, timeLimit: const Duration(seconds: 4));
  } catch (e) {}
}
英文:

**

> Did you try this ?

**

 serviceEnabled = await Geolocator.isLocationServiceEnabled();

    if (serviceEnabled) {
      serviceEnabled = true;
    } else {
      serviceEnabled = false;
    }

    LocationPermission _permission = await Geolocator.checkPermission();

    if (_permission == LocationPermission.denied) {
      _permission = await Geolocator.requestPermission();
      if (_permission == LocationPermission.always || _permission == LocationPermission.whileInUse) {
        permissionGranted = true;
      } else {
        permissionGranted = false;
      }
    } else {
      if (_permission == LocationPermission.always || _permission == LocationPermission.whileInUse) {
        permissionGranted = true;
      } else {
        permissionGranted = false;
      }
    }

    if (serviceEnabled && permissionGranted) {
      try {
        locationData = await Geolocator.getCurrentPosition(desiredAccuracy: LocationAccuracy.bestForNavigation, timeLimit: const Duration(seconds: 4));
      } catch (e) {}
    }

huangapple
  • 本文由 发表于 2023年4月4日 05:40:43
  • 转载请务必保留本文链接:https://go.coder-hub.com/75923972.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定