Flutter Location service no response
308
serviceEnabled = await Geolocator.isLocationServiceEnabled();
if (!serviceEnabled) {
Location loc = Location();
serviceEnabled = await loc.requestService();
if (!serviceEnabled) {
return Future.error('Location services are disabled.');
}
}
geolocator: ^7.7.1
Comments
-
Ahmet Aziz Beşli over 1 year
I am delevoping an app with gMaps and in my application I am getting location permission from user and after that I am requesting the user to turn his/her gps on. The problem is when the gps is turned on for the first time, Application is not able to get the location data.
This is where my program is stuck:
_locationData = await location.getLocation(); print(_locationData.latitude);
After calling this lines, there is no message in the logcat. I think I am not able to get the location data from the provider.
void getPermissions() async { Location location = new Location(); bool _serviceEnabled; PermissionStatus _permissionGranted; _permissionGranted = await location.hasPermission(); if (_permissionGranted == PermissionStatus.denied) { _permissionGranted = await location.requestPermission(); if (_permissionGranted != PermissionStatus.granted) { print('whats happening!'); return; } } _serviceEnabled = await location.serviceEnabled(); if (!_serviceEnabled) { _serviceEnabled = await location.requestService(); print('hahahahahahahahahahahahahah' + _serviceEnabled.toString()); if (!_serviceEnabled) { return; } } _locationData = await location.getLocation(); print(_locationData.latitude); controller.animateCamera(CameraUpdate.newLatLng( new LatLng(_locationData.latitude, _locationData.longitude))); }
-
Just Apps almost 2 yearsHi, did you fix it? I have the same problem.
-
Ahmet Aziz Beşli almost 2 years@JustApps I remember that I used different library to fix it, I will add it to the answers just in a sec
-