【发布时间】:2019-05-22 12:30:00
【问题描述】:
我们开发了一个像 ola 和 uber 这样的外卖应用。骑手可以在哪里接受订单并交付给客户。我们已经创建了一个 android 服务(后台服务),我们已经初始化了我们的位置变量。我们通过 3 种方法获取位置,网络提供商、Gps 提供商、Google Fused 位置 API。所有这三个我们都用来获取一个位置,当我们得到一个位置时,它存储到我们的成员变量中(后来它在辅助项目中使用),并且相同的位置被保存到我们的服务器中以对抗该骑手。我们具体面临2或3个问题。 1.有时用户位置是正确的,在 20-30 秒内我们得到了一些错误的位置,准确度说 > 50 或 100。 2.有些时间位置卡了几分钟或者卡了一个小时。
我们正在使用 Google 规定的专门定位策略。下面是示例。
private static final int TWO_MINUTES = 1000 * 60 * 2;
/** Determines whether one Location reading is better than the current Location fix
* @param location The new Location that you want to evaluate
* @param currentBestLocation The current Location fix, to which you want to compare the new one
*/
protected boolean isBetterLocation(Location location, Location currentBestLocation) {
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;
// Check if the old and new location are from the same provider
boolean isFromSameProvider = isSameProvider(location.getProvider(),
currentBestLocation.getProvider());
// Determine location quality using a combination of timeliness and accuracy
if (isMoreAccurate) {
return true;
} else if (isNewer && !isLessAccurate) {
return true;
} else if (isNewer && !isSignificantlyLessAccurate && isFromSameProvider) {
return true;
}
return false;
}
/** Checks whether two providers are the same */
private boolean isSameProvider(String provider1, String provider2) {
if (provider1 == null) {
return provider2 == null;
}
return provider1.equals(provider2);
}
if (isMoreAccurate)
{
return true;
}
else if (isNewer && !isLessAccurate)
{
return true;
}
else if (isNewer && !isSignificantlyLessAccurate && isFromSameProvider)
{
return true;
}
return false;
我不知道下一步该做什么。
我已经集成了网络提供、GPS 提供者和融合位置提供者。我正在获取位置,但不太准确。我还维护了最近 10 个连续位置的列表。当我收到第 11 个位置时,我搜索到列表,如果发现所有位置都相同(这意味着位置被卡住),那么我清除了我的列表并通过停止并使用新连接再次重新启动服务来删除位置连接。
【问题讨论】: