我在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位置时效果非常好。
答案 0 :(得分:1)
如果新位置为&#34;更好&#34>,您可以决定每个位置更新。比目前的最佳位置。这样可以避免超出所需的准确度:
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;
}
答案 1 :(得分:0)
如果您只对来自GPS的数据感兴趣,可以LocationManager使用GPS_PROVIDER。如果您只对GPS感兴趣,我认为使用FusedLocationProviderApi没有任何好处。