1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
| btn_near.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (c==0) {
ShowSQLiteDBdata(t1,t2);
c=c+1;
}else {
listsiteproche.setAdapter(null);
ListAdapter.notifyDataSetChanged();
ShowSQLiteDBdata(t1,t2);
}
}
});
private void ShowSQLiteDBdata(EditText edittext1,EditText edittext2) {
Location userLoc = new Location("service Provider");
Location siteLoc = new Location("service Provider");
SQLITEDATABASE = SQLITEHELPER2.getWritableDatabase();
cursor = SQLITEDATABASE.rawQuery("SELECT DISTINCT Code,Support,N,E FROM table_los", null);
cod.clear();
Suppor.clear();
azm.clear();
dist.clear();
list1.clear();
list0.clear();
code.clear();
Support.clear();
north.clear();
east.clear();
int i = 0;
if (cursor.moveToFirst()) {
do {
code.add(cursor.getString(cursor.getColumnIndex(SQLiteHelper2.KEY_ID)));
Support.add(cursor.getString(cursor.getColumnIndex(SQLiteHelper2.KEY_Subject)));
north.add(cursor.getString(cursor.getColumnIndex(SQLiteHelper2.KEY_Name)));
east.add(cursor.getString(cursor.getColumnIndex(SQLiteHelper2.KEY_PhoneNumber)));
double salati = Double.parseDouble(north.get(i));
double salongi = Double.parseDouble(east.get(i));
double malati = Double.parseDouble(edittext1.getText().toString());
double malongi = Double.parseDouble(edittext2.getText().toString());
userLoc.setLatitude(malati);
userLoc.setLongitude(malongi);
siteLoc.setLatitude(salati);
siteLoc.setLongitude(salongi);
double distTo = userLoc.distanceTo(siteLoc)/1000;
distTo= (double)Math.round(distTo * 100) / 100;
float bearTo = userLoc.bearingTo(siteLoc);
bearTo= (float)Math.round(bearTo * 100) / 100; //deux chiffres apres virgule
if (bearTo<0) {bearTo=bearTo+360;}
dis.add(distTo);
az.add(String.valueOf(bearTo));
list0.add(new Listsites(code.get(i),Support.get(i),az.get(i),dis.get(i)));
i++;
} while (cursor.moveToNext());
}
//tri
double m=1000.0;
for(int j=0;j<list0.size();j++) {
for (i = 0; i < list0.size(); i++) {
if (m < list0.get(i).getDis())
m = m;
else
m = list0.get(i).getDis();
}
for(int k=0;k<list0.size();k++) {
if (m == list0.get(k).getDis()) {
list1.add(new Listsites(list0.get(k).getCode(), list0.get(k).getSupport(), list0.get(k).getAz(), list0.get(k).getDis()));
list0.get(k).setDis(1000);
}
}
m=1001;
}
for(i=0;i<50;i++){ //list1.size()
cod.add(list1.get(i).getCode());
Suppor.add(list1.get(i).getSupport());
azm.add(list1.get(i).getAz());
dist.add(String.valueOf(list1.get(i).getDis()));
}
ListAdapter = new SQLiteListAdapter(MainGPSActivity.this,
cod,
Suppor,
azm,
dist
);
listsiteproche.setAdapter(ListAdapter);
//final int n = i;
cursor.close();
} |
Partager