Location is not being fetched in OnePlus 6, 7 and 8 devices. Also the location permission popup shows up twice.
geolocator: ^5.3.1
final Geolocator geolocator = Geolocator()..forceAndroidLocationManager;
@override
void initState() {
_getCurrentLocation();
super.initState();
}
_getCurrentLocation() async {
final PermissionStatus permission = await _getLocationPermission();
if (permission == PermissionStatus.granted) {
geolocator
.getCurrentPosition(desiredAccuracy: LocationAccuracy.best)
.then((Position position) {
setState(() {
_currentPosition = position;
});
currentPosition =
LatLng(_currentPosition.latitude, _currentPosition.longitude);
_getAddressFromLatLng();
}).catchError((e) {
print(e);
});
}
}
_getAddressFromLatLng() async {
try {
List<Placemark> p = await geolocator.placemarkFromCoordinates(
_currentPosition.latitude, _currentPosition.longitude);
Placemark place = p[0];
setState(() {
currentAddress = "${place.subLocality}";
});
locationAddress = currentAddress;
} catch (e) {
print(e);
}
}
Future<PermissionStatus> _getLocationPermission() async {
final PermissionStatus permission = await LocationPermissions()
.checkPermissionStatus(level: LocationPermissionLevel.location);
if (permission != PermissionStatus.granted) {
final PermissionStatus permission = await LocationPermissions()
.requestPermissions(
permissionLevel: LocationPermissionLevel.location);
locationPermission = permission;
return permission;
} else {
locationPermission = permission;
return permission;
}
}
Version: geolocator: ^5.3.1
Platform:
Android OS version:
10.3.3
[√] Flutter (Channel stable, v1.17.0, on Microsoft Windows [Version 10.0.18362.836], locale en-ID)
• Flutter version 1.17.0 at D:\applns\flutter_windows_v1.12.13+hotfix.9-stable\flutter
• Framework revision e6b34c2b5c (5 weeks ago), 2020-05-02 11:39:18 -0700
• Engine revision 540786dd51
• Dart version 2.8.1
[√] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
• Android SDK at C:\Users\A-9295\AppData\Local\Android\sdk
• Platform android-R, build-tools 29.0.3
• Java binary at: D:\applns\Android Studio\jre\bin\java
• Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1343-b01)
• All Android licenses accepted.
[√] Android Studio (version 3.4)
• Android Studio at D:\applns\Android Studio
• Flutter plugin version 39.0.1
• Dart plugin version 183.6270
• Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1343-b01)
[√] Connected device (2 available)
• XT1068 • ZX1D64FH5B • android-arm • Android 6.0 (API 23)
• AOSP on IA Emulator • emulator-5554 • android-x86 • Android 9 (API 28) (emulator)
• No issues found!
Same on Huawei P30
It was same here in Xiaomi Mi 8 SE.
But, the code below works for me
Future<void> getLocation() async {
try {
Geolocator geolocator = Geolocator()..forceAndroidLocationManager = true;
Position position = await geolocator.getCurrentPosition(
desiredAccuracy: LocationAccuracy.low,
);
print(position);
} catch (error) {
print(error.message);
}
}
Any update on this Also not getting a location on Xiaomi Mi
小米Mi 8 SE中的情况与此相同。
但是,下面的代码对我有用
Future<void> getLocation() async { try { Geolocator geolocator = Geolocator()..forceAndroidLocationManager = true; Position position = await geolocator.getCurrentPosition( desiredAccuracy: LocationAccuracy.low, ); print(position); } catch (error) { print(error.message); } }
xiaomi 10 effective
Awesome let me check that out
geolocator.getCurrentPosition(desiredAccuracy: LocationAccuracy.medium);
/// I set it to medium
LocationAccuracy.medium
Seems al these devices don't have Google Play Services installed. So using .forceAndroidLocationManager = true should fix this issue.
You could also try the latest release 6.0.0-rc.3 which has beter support for detecting if Google Play Services are installed internally.
Most helpful comment
Any update on this Also not getting a location on Xiaomi Mi