开发者

Android Location.getAccuracy() returns 1

开发者 https://www.devze.com 2023-01-25 13:23 出处:网络
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 map开发者_StackOverflow社区s is telling me

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 map开发者_StackOverflow社区s is telling me my current location accuracy is 40 meters.

Any thoughts?

int accuracy = (int) loc.getAccuracy();
// This will give me accuracy = 1


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.)


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)


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


I usually have 6-9 satelites visible (Scandinavia) and get around 2.0 meters for getAccuracy() - and it turns out, in practice, to be around +|- 40 cm accurate in reality.

0

精彩评论

暂无评论...
验证码 换一张
取 消