馃悰 Bug Report
Summary description of the bug:
I try use geolocator and him work in android 7 ++, but in android 5.1 and android 6 not.
Reproduction steps:
1)Add ACCESS_COARSE_LOCATION and ACCESS_FINE_LOCATION into Android Manifest;
2)Add dependencie.
3)Import geolocator;
4)Check if have permission (return 'true').
5)Try get location (return error).
Code:
import 'package:geolocator/geolocator.dart';
import 'package:flutter/material.dart';
class TelaRegistrarLoc extends StatefulWidget {
@override
_TelaRegistrarLocState createState() => _TelaRegistrarLocState();
}
class _TelaRegistrarLocState extends State<TelaRegistrarLoc> {
_handleSubmit(BuildContext context) async {
bool isLocationServiceEnabled = await Geolocator.isLocationServiceEnabled();
print("service is enable? " + isLocationServiceEnabled.toString());
Position position = await Geolocator.getCurrentPosition(desiredAccuracy: LocationAccuracy.low);
print(position);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Location"),
),
body: Button()
);
}
Button() {
return Center(
child: Container(
width: 100,
height: 100,
margin: EdgeInsets.all(8),
child: Ink(
decoration: const ShapeDecoration(
color: Colors.blue,
shape: CircleBorder(),
),
child: IconButton(
iconSize: 60,
color: Colors.white,
icon: Icon(Icons.add_location),
onPressed: () => _handleSubmit(context)
)
)
)
);
}
}
Console return:
I/flutter ( 4012): service is enable? true
E/flutter ( 4012): [ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: The location service on the device is disabled.
Platform:
Hi @robertoalvesneto,
Today I have released version 6.1.10 of the geolocator plugin which solved issue #585. This issue looks very similar, can you maybe verify if it also solves your problem?
Hi @mvanbeusekom
Don't solve.
Before is only worked when i didn't inform 'desiredAccuracy', now work when i inform high and best.
I updated the code to try help:
_handleSubmit(BuildContext context) async {
await get_location('LOW');
await get_location('MEDIUM');
await get_location('HIGH');
await get_location('BEST');
await get_location('NO_INFORMATION');
}
void get_location(accuracy) async {
bool _isLocationServiceEnabled = await Geolocator.isLocationServiceEnabled();
LocationAccuracy _location;
Position _position;
switch(accuracy) {
case 'LOW': _location = LocationAccuracy.low; break;
case 'MEDIUM': _location = LocationAccuracy.medium; break;
case 'HIGH': _location = LocationAccuracy.high; break;
case 'BEST': _location = LocationAccuracy.best; break;
}
try {
if (accuracy == 'NO_INFORMATION') {
_position = await Geolocator.getCurrentPosition()
.timeout(Duration(seconds: 10));
} else {
_position = await Geolocator.getCurrentPosition(
desiredAccuracy: _location
).timeout(Duration(seconds: 10));
}
print("$accuracy:: isLocationServiceEnabled: $_isLocationServiceEnabled position: $_position");
} catch (e) {
print("$accuracy:: isLocationServiceEnabled: $_isLocationServiceEnabled error: $e");
}
}
Output is:
Performing hot reload...
Syncing files to device Android SDK built for x86...
Reloaded 2 of 552 libraries in 246ms.
I/flutter ( 4008): LOW:: isLocationServiceEnabled: true error: TimeoutException after 0:00:10.000000: Future not completed
I/flutter ( 4008): MEDIUM:: isLocationServiceEnabled: true error: TimeoutException after 0:00:10.000000: Future not completed
I/flutter ( 4008): HIGH:: isLocationServiceEnabled: true position: Latitude: 37.4219983, Longitude: -122.084
I/flutter ( 4008): BEST:: isLocationServiceEnabled: true position: Latitude: 37.4219983, Longitude: -122.084
I/flutter ( 4008): NO_INFORMATION:: isLocationServiceEnabled: true position: Latitude: 37.4219983, Longitude: -122.084
Hi @robertoalvesneto
Are you experiencing this issue on an AVD or a physical device?
Hi @robertoalvesneto
Are you experiencing this issue on an AVD or a physical device?
Hi, in AVD
Hi @robertoalvesneto
I think the reason why the accuracy low and medium are not working is because the AVD is not able to simulate some things Geolocator needs.
When using these accuracies Geolocator (or rather the FusedLocationProviderClient Api which Geolocator uses by default on android) strongly prefers cell reception and WIFI to determine a location, because it saves battery.
However on the AVD there is no cell reception and the WIFI is abstract as just a network connection. So it is not getting a response, and eventually the TimeoutException will occur.
When using high and best you tell Geolocator to preferably use GPS, which the AVD can simulate.
So this is an issue outside of their control, I think.
Links:
Stack Overflow problem
Documentation showing different accuracies
Hi @Sempakonka
I agree, so i close issue?
Hi @robertoalvesneto
If this issue does not persist on a physical device than I think this issue can be closed.
Most helpful comment
Hi @robertoalvesneto
I think the reason why the accuracy
lowandmediumare not working is because the AVD is not able to simulate some things Geolocator needs.When using these accuracies Geolocator (or rather the FusedLocationProviderClient Api which Geolocator uses by default on android) strongly prefers cell reception and WIFI to determine a location, because it saves battery.
However on the AVD there is no cell reception and the WIFI is abstract as just a network connection. So it is not getting a response, and eventually the
TimeoutExceptionwill occur.When using
highandbestyou tell Geolocator to preferably use GPS, which the AVD can simulate.So this is an issue outside of their control, I think.
Links:
Stack Overflow problem
Documentation showing different accuracies