2012-04-02 1 views
0

これは、開発者サイトがより良い修正を得るために提供しているコードスニペットです。私はこれに疑問がある。この実装では、関数はそれが大幅に新しいかどうかをチェックします。しかし、新しい修正がネットワークプロバイダからのものであって、それがあまり正確でない場合はどうでしょうか?まだそれは真実を返すが、そうであってはならない。これはバグですか、私の理解が間違っていますか?Android:開発者サイトのより良い位置情報の修正に関するガイドライン

リンク:http://developer.android.com/guide/topics/location/obtaining-user-location.html

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; 

}

答えて

0

大幅に新しい場所が多くのことを変更しましたので、でも、ネットワークの場所のフィックスが古いGPS位置の修正よりも正確であることを意味します。そう、それは理にかなっている。

しかし、私はあなたの考えは、最高の場所のソースを優先することは良いと思う、あなたはそれを実装し、2つの異なるソースから2つの異なる修正を維持する必要があります。

あなたが触発したチュートリアルへのリンクを提供することは良いことでした。

+0

私はリンクを追加しました、私はそれが人が移動していない可能性があり、彼は低いネットワークカバレッジエリアであり、場所の修正がない可能性がありますので、正確である。それは意味をなさない? if(isSignificantlyNewer && isMoreAccurate)です。 –

+0

私はそうは思わない。修正が大幅に新しい場合は、前回の修正を破棄する必要があることを意味します。人が移動していない場合は、もう一度gpsの位置情報を取得し直してください(以前にあった場合)。 – Snicolas

+0

私はネットワークプロバイダーの修正を考慮に入れていました。低いカバレッジエリアでは、ネットワークプロバイダの修正のみが含まれているケースがあります。 –

関連する問題