0

我在我的 Android 应用程序中使用 fusedlocationproviderapi 来传输用户位置。这可以正常工作,但有时该位置会跳转到城镇中的某个位置,然后会显示相同的位置。我相信该应用程序从 GPS 切换到手机信号塔试用版,在我们地区这并不好用。(MN)我使用

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

在清单文件中,我会很好地忽略错误位置或检测这些位置而不传输这些位置。

mLocationRequest = LocationRequest.create();
    mLocationRequest.setInterval(UpdateSeconds * 1000);
    mLocationRequest.setFastestInterval(UpdateSeconds * 1000);
    mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);

我使用上面的代码,当我获得 GPS 位置时效果很好。

4

2 回答 2

1

如果新位置比当前最佳位置“更好”,您可以决定每次位置更新。这样可以避免跳出您所需的准确性:

protected boolean isBetterLocation(Location location,
        Location currentBestLocation) {
    final int TWO_MINUTES = 1000 * 60 * 2;

    if (currentBestLocation == null) {
        // A new location is always better than no location
        return true;
    }

    // Check whether the new location fix is newer or older
    long timeDelta = location.getTime() - currentBestLocation.getTime();
    boolean isSignificantlyNewer = timeDelta > TWO_MINUTES;
    boolean isSignificantlyOlder = timeDelta < -TWO_MINUTES;
    boolean isNewer = timeDelta > 0;

    // If it's been more than two minutes since the current location, use
    // the new location
    // because the user has likely moved
    if (isSignificantlyNewer) {
        return true;
        // If the new location is more than two minutes older, it must be
        // worse
    } else if (isSignificantlyOlder) {
        return false;
    }

    // Check whether the new location fix is more or less accurate
    int accuracyDelta = (int) (location.getAccuracy() - currentBestLocation
            .getAccuracy());
    boolean isLessAccurate = accuracyDelta > 0;
    boolean isMoreAccurate = accuracyDelta < 0;
    boolean isSignificantlyLessAccurate = accuracyDelta > 200;

    // Determine location quality using a combination of timeliness and
    // accuracy
    if (isMoreAccurate) {
        return true;
    } else if (isNewer && !isLessAccurate) {
        return true;
    } else if (isNewer && !isSignificantlyLessAccurate) {
        return true;
    }
    return false;
}
于 2015-05-18T13:44:21.213 回答
0

如果您只对来自 GPS 的数据感兴趣,则可以将LocationManagerGPS_PROVIDER一起使用。如果您只对 GPS 感兴趣,我认为使用 FusedLocationProviderApi 没有任何好处。

于 2015-05-15T05:58:34.967 回答