I have a database that has the fields, latitude and longitude.
I'll get the bd through this function,and convert to an array.
ArrayList<PontoEntity> array = new ArrayList<PontoEntity>();
Cursor c = com.vianaturismo.db.DBMain.getAll(getApplicationContext(), DALPonto.TABLE_NAME, DALPonto.columns);
array = DALPonto.converte(c);
She also has this function to return the distance between where I am and point.
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*/
}
My difficulty in this sort the array by distance. That is, sort by closest point.