Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Location.getAccuracy() returns 1

Tags:

java

android

gps

I'm trying to get my current GPS accuracy by using Location.getAccuracy(). However, this is returning 1 (or sometimes 2) which doesn't seem possible. Google maps is telling me my current location accuracy is 40 meters.

Any thoughts?

int accuracy = (int) loc.getAccuracy();
// This will give me accuracy = 1
like image 756
TomBomb Avatar asked Nov 13 '10 22:11

TomBomb


3 Answers

From the documentation of getAccuracy:

Returns the accuracy of the fix in meters.

Why doesn't it seem possible? A return-value of 1, sometimes 2 meters, is perfectly fine for GPS. With a good signal strength, and locks on multiple satellites, you can get that kind of accuracy.

(Besides, since you're casting to an int your flooring the value. The accuracy may actually be for instance 1.9 meters.)

like image 83
aioobe Avatar answered Nov 14 '22 20:11

aioobe


Is it possible that you are calling getAccuracy() on the LocationProvider and not the Location? From the docs:

public abstract int getAccuracy ()

Since: API Level 1 Returns a constant describing horizontal accuracy of this provider. If the provider returns finer grain or exact location, ACCURACY_FINE is returned, otherwise if the location is only approximate then ACCURACY_COARSE is returned.

Where ACCURACY_FINE and ACCURACY_COARSE are defined as:

public static final int ACCURACY_COARSE

Since: API Level 1 A constant indicating an approximate accuracy requirement

Constant Value: 2 (0x00000002)
public static final int ACCURACY_FINE

Since: API Level 1 A constant indicating a finer location accuracy requirement

Constant Value: 1 (0x00000001)
like image 22
rindress Avatar answered Nov 14 '22 21:11

rindress


40 meters looks more like cellular network accuracy, but not GPS.

like image 1
Andrey Novikov Avatar answered Nov 14 '22 21:11

Andrey Novikov