TimeoutException while using Geolocator in Flutter

import 'package:geolocator/geolocator.dart';Future<void> getCoordinates() async {
try {
Position position = await Geolocator.getCurrentPosition(
desiredAccuracy: LocationAccuracy.low,

);

print(position.latitude);
print(position.longitude);
} catch (e) {
print(e.toString());
}
}

Give me a Moment to explain what the code is doing ( for fresher in this stream)…

It is trying to access the current position of the device, basically longitude and latitude of the current device.While desiredAccuracy: is telling the function the how much accurate position we want. Like if it is okay for us that the position is here-there by few kms or not.And we are giving the parameter LocationAccuracy.low so now we are telling that we want that you can put accuracy as low and we are fine with it, so that device battery and other components are not affected.
import 'package:geolocator/geolocator.dart';Future<void> getCoordinates() async {
try {
Position position = await Geolocator.getCurrentPosition(
desiredAccuracy: LocationAccuracy.low,
timeLimit: Duration(seconds: 10),
);

print(position.latitude);
print(position.longitude);
} catch (e) {
print(e.toString());
}
}
Output:
29.3643355
59.4304381

Timeout Exception happen in geolocator because of timelimit, so we can increase it to get the specific result.

Thanks For Reading, Follow Me For More

Annyeongヾ(•ω•`)o

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store