Sub topic 9
Coarse, Fine, and Approximate Location
Assume you know basic Dart, Flutter widgets, async/await, and how to add a package to pubspec.yaml. This chapter uses the geolocator package and focuses on the accuracy of a location result, not on map rendering.
What the Accuracy Levels Mean
Location accuracy describes how closely a reported position matches the device's real position. It does not describe whether your app is allowed to use location. Permission and accuracy are related, but they are separate decisions.
| Term | Meaning | Suitable examples |
|---|---|---|
| Coarse location | A broad area, often based on Wi-Fi or cell data | Local weather, regional content |
| Fine location | A more exact position, often using GPS | Turn-by-turn navigation, nearby pickup |
| Approximate location | A user-selected reduction in precision | Apps that only need a general area |
On Android, users can often grant approximate or precise location when the app asks for location. A precise request does not force the user to grant precise access. On iOS, users can turn off Precise Location for an app. The app then receives an approximate position even when it has permission to use location while in use.
A platform permission declaration enables a request, but it does not guarantee a particular accuracy level. Your feature must continue to work when the user chooses less precision.
Requesting a Position
Declare the required permissions before requesting location at runtime. For example, Android commonly declares coarse and fine access:
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />Your iOS Info.plist must include a clear usage description:
<key>NSLocationWhenInUseUsageDescription</key>
<string>We use your location to show nearby places while the app is open.</string>Then request a position with an accuracy preference:
import 'package:geolocator/geolocator.dart';
Future<Position> readPosition() async {
final serviceEnabled = await Geolocator.isLocationServiceEnabled();
if (!serviceEnabled) {
throw StateError('Turn on location services and try again.');
}
var permission = await Geolocator.checkPermission();
if (permission == LocationPermission.denied) {
permission = await Geolocator.requestPermission();
}
if (permission == LocationPermission.denied ||
permission == LocationPermission.deniedForever) {
throw StateError('Location permission is unavailable.');
}
return Geolocator.getCurrentPosition(
locationSettings: const LocationSettings(
accuracy: LocationAccuracy.high,
),
);
}LocationAccuracy.high tells the operating system that your feature prefers a precise result. It may use more battery and may take longer to obtain a fix. The operating system can still return an approximate position. Check Position.accuracy when your feature needs to know the estimated error in meters.
Match Accuracy to the Feature
Do not reject a location merely because it is approximate unless precision is essential. For example, a nearby restaurant search can widen its search radius when position.accuracy is large. A navigation feature should explain that precise access is required and show a useful error when the result is too uncertain.
Exercise
Exercise
Why can LocationAccuracy.high still produce an approximate position?
Show answer
It is only the app's preferred accuracy. The operating system and the user's permission choice control the maximum precision available.