In the Criteria
class, there are two constants, ACCURACY_HIGH
and ACCURACY_FINE
, which are apparently used to require the LocationManager
to return higher accuracy location updates. Here is what the documentation says about each of these constants:
public static final int ACCURACY_FINE (Added in API level 1)
A constant indicating a finer location accuracy requirement Constant Value: 1 (0x00000001)
public static final int ACCURACY_HIGH (Added in API level 9)
a constant indicating a high accuracy requirement - may be used for horizontal, altitude, speed or bearing accuracy. For horizontal and vertical position this corresponds roughly to an accuracy of less than 100 meters. Constant Value: 3 (0x00000003)
Does anyone know which of these two constants provides (i.e. requires) the highest level of accuracy?
A class indicating the application criteria for selecting a location provider. Providers may be ordered according to accuracy, power usage, ability to report altitude, speed, bearing, and monetary cost.
From what I can see in the source code, ACCURACY_FINE is grouped with ACCURACY_COARSE with constant values of 1 & 2 respectively. ACCURACY_LOW, MEDIUM and HIGH are grouped together with constant values 1, 2 & 3.
It seems that setAccuracy expects and returns either COARSE or FINE, while setVerticalAccuracy, setHorizontalAccuracy, setSpeedAccuracy and setBearingAccuracy expect LOW, MEDIUM or HIGH. Furthermore, when you call setAccuracy, it sets horizontal accuracy like so:
public void setAccuracy(int accuracy) {
if (accuracy < NO_REQUIREMENT || accuracy > ACCURACY_COARSE) {
throw new IllegalArgumentException("accuracy=" + accuracy);
}
if (accuracy == ACCURACY_FINE) {
mHorizontalAccuracy = ACCURACY_HIGH;
} else {
mHorizontalAccuracy = ACCURACY_LOW;
}
}
It's really confusing, but I hope I cleared it up for you a bit. Here's a link to the source in grepcode, you can download it and see for yourself if you don't have the source locally.
Both constants mean the highest accuracy, but are intended for different methods. From the documentation (which may have been updated since the question was asked):
ACCURACY_FINE
is valid input for setAccuracy.
ACCURACY_HIGH
is valid input for setBearingAccuracy, setHorizontalAccuracy, setSpeedAccuracy and setVerticalAccuracy.
I believe the idea of this modeling is that FINE
and COARSE
give you a choice of two opposites only, whereas LOW
, MEDIUM
and HIGH
allow for a more subtle distinction. (The question remains, why setSpeedAccuracy
ridicules that modeling by allowing only LOW
and HIGH
. But then, this might be a bug in either documentation or design. :) )
As mentioned by the OP, they introduced those values later, API level 9, in contrast to API level 1 for FINE-COARSE. The code found by npace simply reveals that internally the Android developers now map everything to the names and values of the LOW to HIGH value range, to get some consistency internally.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With