我有一個數據庫,有經度和緯度的字段。排序數組的距離
我將通過此函數獲取bd,並將其轉換爲數組。
ArrayList<PontoEntity> array = new ArrayList<PontoEntity>();
Cursor c = com.vianaturismo.db.DBMain.getAll(getApplicationContext(), DALPonto.TABLE_NAME, DALPonto.columns);
array = DALPonto.converte(c);
她也有這個功能來返回我和我之間的距離。
public double getDistancia(double latitude, double longitude, double latitudePto, double longitudePto){
double dlon, dlat, a, distancia;
dlon = longitudePto - longitude;
dlat = latitudePto - latitude;
a = Math.pow(Math.sin(dlat/2),2) + Math.cos(latitude) * Math.cos(latitudePto) * Math.pow(Math.sin(dlon/2),2);
distancia = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
return 6378140 * distancia; /* 6378140 is the radius of the Earth in meters*/
}
我在這種排序距離的困難。也就是說,按最近的點排序。
如果您問題是與排序數據引用此:http://stackoverflow.com/questions/19495642/java-sorting-text-file-lines/19496006#19496006 – Tyler