我可以使用 fusedlocationproviderapi 并强制仅使用 GPS 吗?

Can I use fusedlocationproviderapi and force using GPS only?

我在 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 位置时效果很好。

如果您只对来自 GPS 的数据感兴趣,可以使用 LocationManager with GPS_PROVIDER。如果您只对 GPS 感兴趣,我认为使用 FusedLocationProviderApi 没有任何好处。

如果新位置比当前最佳位置 "better",您可以决定每次位置更新。这样可以避免超出您要求的准确度:

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;
}