Sub topic 9
Coarse, fine, and approximate location
This chapter assumes you can declare permissions in AndroidManifest.xml and Info.plist, and that you have the check-then-request flow from the earlier chapters. It covers the second question a location feature must answer once permission is granted: how precise is the location you are allowed to see?
Two ways to say "how precise"
Three words are easy to mix up.
- Coarse and fine are Android permission names.
ACCESS_COARSE_LOCATIONgives a rough position.ACCESS_FINE_LOCATIONgives a precise one. - Approximate and precise are the labels users see in the system dialogs (Android 12 and later, iOS 14 and later).
LocationAccuracyis a geolocator setting. It states how accurate a result you would like, and it does not grant anything.
The user's choice is the upper limit. Your LocationAccuracy setting can ask for less than that limit, but it cannot get more.
| Term | Where it lives | Who decides |
|---|---|---|
| `ACCESS_COARSE_LOCATION`, `ACCESS_FINE_LOCATION` | Android manifest | You declare, the user grants |
| Precise / Approximate toggle | Android 12+ and iOS 14+ dialogs | The user |
| `LocationAccuracy.high`, `.reduced`, and so on | `LocationSettings` in Dart | You request, the OS may deliver less |
What approximate location gives you
An approximate fix is deliberately blurred by the operating system.
- On Android, an approximate location is accurate to roughly a 3 square kilometer area.
- On iOS, reduced accuracy places the user in a region that can be several kilometers wide. iOS may also refresh it only a few times per hour.
Approximate location is enough for a weather forecast, a city-level store finder, or regional content. It is not enough for turn-by-turn navigation, "nearest bus stop", or delivery tracking. Decide which group your feature belongs to before you write any code. That decision determines what you declare and how you react to a reduced grant.
Declaring the right entries
On Android you declare both permissions, as in the earlier chapter:
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<application ...>
...
</application>
</manifest>Three rules apply on Android 12 (API 31) and later.
- If you request fine location, you must declare and request coarse location too. A request for fine alone is not allowed.
- If you declare only coarse, the user never sees the precise option, and you only ever receive approximate positions. This is a good choice when your feature really is city-level, because it asks for less.
- When both are requested, the dialog shows Precise and Approximate options. The user may pick Approximate even though you declared fine.
On iOS there is no separate permission string for precision. The same NSLocationWhenInUseUsageDescription covers both. The precision choice is a toggle inside the permission dialog and in Settings.
Two optional Info.plist keys relate to precision:
<key>NSLocationDefaultAccuracyReduced</key>
<true/>
<key>NSLocationTemporaryUsageDescriptionDictionary</key>
<dict>
<key>NavigationPurpose</key>
<string>Precise location lets us show the exact walking route to your destination.</string>
</dict>NSLocationDefaultAccuracyReducedmakes the app start in reduced mode, so the user must opt in to precise location. Use it when your app does not need precision.NSLocationTemporaryUsageDescriptionDictionaryholds one or more purpose keys. Each key maps to the text of a one-time dialog that asks for full accuracy. The key name (NavigationPurposehere) is one you choose, and you pass it to the Dart call shown later.
The permission state does not tell you the precision
This is the most common mistake. Suppose the user picks Approximate in the dialog. Geolocator.checkPermission() then returns LocationPermission.whileInUse, exactly as it would for a precise grant. The permission is granted, and the precision is a separate fact.
The permission_handler package has the same limit. Permission.locationWhenInUse.status reports granted for both choices, so it cannot tell you the precision either.
To learn the precision, ask geolocator directly:
import 'package:geolocator/geolocator.dart';
Future<bool> hasPreciseLocation() async {
final status = await Geolocator.getLocationAccuracy();
return status == LocationAccuracyStatus.precise;
}getLocationAccuracy() returns a LocationAccuracyStatus, either precise or reduced. Call it after permission is granted. The user can change the toggle in system settings at any time, so check again when it matters, for example when the app resumes.
Reacting to a reduced grant
You have three sensible options, in order of preference.
- Work with it. If your feature tolerates approximate data, continue and show a hint such as "Showing results for your general area".
- Ask for a temporary upgrade (iOS).
requestTemporaryFullAccuracyshows a one-time dialog using the text you stored under your purpose key. If the user agrees, you get full accuracy until the app is closed or moved to the background for a while. - Explain and send them to settings. On Android there is no temporary upgrade call. If precision is essential, explain why, then use
Geolocator.openAppSettings()so the user can switch the toggle.
The following function combines the permission flow with the precision check:
import 'package:geolocator/geolocator.dart';
enum LocationQuality { precise, approximate, unavailable }
Future<LocationQuality> ensureLocation({required bool needsPrecise}) async {
var permission = await Geolocator.checkPermission();
if (permission == LocationPermission.denied) {
permission = await Geolocator.requestPermission();
}
final granted = permission == LocationPermission.whileInUse ||
permission == LocationPermission.always;
if (!granted) {
return LocationQuality.unavailable;
}
var status = await Geolocator.getLocationAccuracy();
if (status == LocationAccuracyStatus.reduced && needsPrecise) {
// Shows a one-time dialog on iOS. Check the plugin docs for Android behavior.
status = await Geolocator.requestTemporaryFullAccuracy(
purposeKey: 'NavigationPurpose',
);
}
return status == LocationAccuracyStatus.reduced
? LocationQuality.approximate
: LocationQuality.precise;
}The function returns after the upgrade attempt, so the caller always receives the final state. The caller decides what to show: a map with a pin for precise, a city label for approximate, and the settings redirect from the previous chapter for unavailable.
The purpose key must exist in Info.plist. If it is missing, the iOS call fails, so test this path on a real iOS 14+ device or simulator.
flowchart TDRequesting accuracy in position calls
LocationAccuracy in LocationSettings is your side of the bargain. The values run from lowest through low, medium, high, and best to bestForNavigation. There is also reduced, which asks for the coarse source explicitly.
import 'package:geolocator/geolocator.dart';
Future<void> printFix({required bool wantsPrecise}) async {
final settings = LocationSettings(
accuracy: wantsPrecise ? LocationAccuracy.high : LocationAccuracy.reduced,
);
final position = await Geolocator.getCurrentPosition(
locationSettings: settings,
);
print('lat ${position.latitude}, lng ${position.longitude}');
print('reported accuracy: ${position.accuracy} m');
}position.accuracy is the estimated horizontal error in meters. Use it to check what you really received. A request for LocationAccuracy.high under an approximate grant still returns a blurred position, and the value in accuracy will be in the thousands of meters. Do not assume high means a precise fix.
Accuracy also costs power. Higher settings keep GPS hardware active longer, so choose the lowest level that serves the feature. For a one-off "what city am I in" lookup, LocationAccuracy.low or reduced is faster and cheaper.
Edge cases to plan for
- Downgrade while running. The user can switch from Precise to Approximate in system settings while your app is alive. Positions then arrive with larger
accuracyvalues. Handle this in streams by readingposition.accuracyand not by assuming the first check still holds. - Older OS versions. Android 11 and below, and iOS 13 and below, have no approximate option.
getLocationAccuracy()should report precise there, so the same code works without version checks. - Emulators. Emulated positions are usually exact, so reduced accuracy is hard to see without a device. Mock the accuracy status in tests, as covered in the testing chapter.
- Repeated upgrade prompts. Do not call
requestTemporaryFullAccuracyon every screen. If the user declined once, respect it and offer a clear "Use precise location" button instead.
Summary of decisions
- Decide whether the feature needs precise location. If not, declare coarse only on Android and consider
NSLocationDefaultAccuracyReducedon iOS. - Run the normal permission flow.
- Read the accuracy status separately.
- If it is reduced and you need precision, upgrade temporarily on iOS or explain and open settings on Android.
- Request a
LocationAccuracythat matches the feature, and verifyposition.accuracyin the result.
Exercise
A user taps "Allow" on an Android 13 dialog but selects "Approximate". Your app declared both coarse and fine permissions. What does Geolocator.checkPermission() return, how do you find out the user chose approximate, and what can the app do if it needs a precise position?
Show answer
checkPermission() returns LocationPermission.whileInUse, the same as for a precise grant, because the permission itself is granted. Call Geolocator.getLocationAccuracy() to learn the precision. It returns LocationAccuracyStatus.reduced. You can also check position.accuracy on returned positions. Android has no temporary upgrade call, so the app should explain why precision is needed and send the user to settings with Geolocator.openAppSettings(). It should check the accuracy status again when the app resumes.
Exercise
You call requestTemporaryFullAccuracy(purposeKey: 'NavigationPurpose') on an iOS device and the call fails. Name the most likely configuration cause.
Show answer
The Info.plist has no NSLocationTemporaryUsageDescriptionDictionary entry containing a NavigationPurpose key, so iOS has no text to show in the one-time dialog. Add the dictionary with a key that matches the purposeKey string exactly.