I am trying to get the current geolocation in Flutter using the Geolocator package but it's not working. Here is my function code:
local() async {
final Geolocator geolocator = Geolocator()..forceAndroidLocationManager = true;
var position = await geolocator.getCurrentPosition(desiredAccuracy: LocationAccuracy.low);
print(position);
}
It's printing NULL.
Note : I have set the proper permissions in AndroidManifest along with the geolocator API key.
Geolocator package version : 5.3.0
Flutter Doctor: (I can't use the last version of flutter currently)
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, v1.17.5, on Linux, locale en_US.UTF-8)
[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
[✓] Android Studio (version 3.6)
[✓] VS Code (version 1.48.2)
[✓] Connected device (1 available)
• No issues found!
Didn't find the problem with the Geolocator package, so i used the Locator package and it worked fine.
Here's my function :
import 'package:location/location.dart';
LocationData locationData;
local() async {
Location location = new Location();
locationData = await location.getLocation();
print(locationData);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.