英文:
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
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) {}
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论