我知道Stackover流程中有很多可用的解決方案,但看起來沒有解決我的基本問題 - 我有超過2500個lon/lat數據 - 我想存儲/從sqlite - 根據用戶輸入查詢最近的位置。 尋找最佳的解決方案從SQLite中存儲和檢索位置數據
注:我已經通過 Finding the closest point to a given point
了這是什麼Geohashing所有關於我的這個特殊問題
我知道Stackover流程中有很多可用的解決方案,但看起來沒有解決我的基本問題 - 我有超過2500個lon/lat數據 - 我想存儲/從sqlite - 根據用戶輸入查詢最近的位置。 尋找最佳的解決方案從SQLite中存儲和檢索位置數據
注:我已經通過 Finding the closest point to a given point
了這是什麼Geohashing所有關於我的這個特殊問題
Geohashing如何使用Geohashing是緯度的編碼,經度對這樣的那些接近eaxh的點有一個共同的前綴geohashes。然而,這並不適用於這個星球上的每一個座標,也就是那些鄰近點中goehash變化很大的區域。取決於散列算法,靠近赤道的區域可能是這樣一個區域。 參見這裏瞭解更多詳情:http://en.wikipedia.org/wiki/Geohash
對於一個相對較小的ca. 500個位置我能夠通過搜索0.1度間隔內的點非常快地找到給定參考點(用戶的位置)的最近位置。下面是查詢代碼:
/**
* Query the airfields table for airfields near the given position.
* @param dbCon DB connection
* @param ref_lat latitude
* @param ref_lon longitude
* @return Answer the airfield nearest to the given position as array
* of objects: id, designator, latitude, longitude.
* Answer <code>null</code> if their is no airfield near the
* given position plus or minus 0.1 degrees.
*/
private Object[] rangeQuery(final SQLiteDatabase dbCon, final double ref_lat, final double ref_lon) {
if(DEBUG)
Log.d(TAG, "rangeQuery lat=" + ref_lat + ", lon=" + ref_lon);
final SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
qb.setTables(AirfieldsTable.TABLE_NAME);
final String[] whereArgs = new String[] {
Double.toString(ref_lat - 0.1d), Double.toString(ref_lat + 0.1d),
Double.toString(ref_lon - 0.1d), Double.toString(ref_lon + 0.1d)
};
final Cursor crsr = qb.query(dbCon, allFields(), AirfieldsTable.RANGE_CLAUSE, whereArgs, null, null, null);
final Object[] val = this.scanForNearest(crsr, ref_lat, ref_lon);
crsr.close();
if(DEBUG)
Log.d(TAG, "scanForNearest returned " + val);
return val;
}
如果選擇我直接比較剩餘點多行(那是什麼scanForNearest()一樣)。它的速度足以在記錄器(其日誌應用程序)檢測到着陸後找到機場。
謝謝斯蒂芬,是0.1度更像一般的解決方案,我的需要是前:給定位置的五個最近的位置,實際上我想問的是1.良好的方式來存儲位置數據在sqlite中2.更快查詢說5最近的位置給定的點。我嘗試了靈魂pythogorous定理+邊緣因素,但它非常緩慢地查詢2500個條目數據庫中的5個位置 – Shri 2012-02-14 15:39:34