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 124 125 126
|
public class main extends MapActivity implements LocationListener, OnCancelListener {
private TabHost myTabHost;
private LocationManager locationManager;
private String provider;
private Location localisation;
private long updTime = 15000;
private float udpDistance = 2;
private ProgressDialog dialogWait;
private boolean cancel;
private Thread thread;
private Handler handler;
private LocationListener ll;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
/* Gestion attente*/
dialogWait = new ProgressDialog(this);
dialogWait.setProgressStyle(ProgressDialog.STYLE_SPINNER);
dialogWait.setOnCancelListener(this);
dialogWait.setMessage("Calcul de la position en cours ...");
dialogWait.setCancelable(true);
dialogWait.setMax(100);
dialogWait.show();
/* Gestion des onglets */
myTabHost = (TabHost) findViewById(R.id.tabhost);
myTabHost.setup();
// Paramètres onglets
myTabHost.addTab(myTabHost.newTabSpec("contentTab1").setIndicator("Afficher",getResources().getDrawable(R.drawable.computer)).setContent(R.id.contentTab1));
myTabHost.addTab(myTabHost.newTabSpec("contentTab2").setIndicator("Rechercher",getResources().getDrawable(R.drawable.page)).setContent(R.id.contentTab2));
handler = new Handler(){
public void handleMessage(Message msg){
switch(msg.what){
case 0:
Toast.makeText(main.this, "???", Toast.LENGTH_SHORT).show();
break;
case 1:
dialogWait.dismiss();
/* Initialisation aprés localisation */
// Récupération convertion Lambert
double[] tabLambert = convertToLambert(localisation);
((TextView)findViewById(R.id.textLambert)).setText(String.valueOf("Lat : " + floor(localisation.getLatitude(), 5)+" - Lng : " + floor(localisation.getLongitude(), 5)));
// Récupération convertion Dfci
String posDfci = convertToDfci(tabLambert[0], tabLambert[1]);
((TextView)findViewById(R.id.textDfci)).setText(String.valueOf(posDfci));
// Récupération convertion en degré en minutes et secondes
String posDms = convertToDms(localisation.getLatitude(), localisation.getLongitude());
((TextView)findViewById(R.id.textGeodesique)).setText(String.valueOf(posDms));
// Récupération adresse
convertAdresse(localisation.getLatitude(), localisation.getLongitude());
break;
}
}
};
thread = new Thread(){
public void run(){
/* Gestion service de localisation */
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
// Dernière position récupérée
localisation = locationManager.getLastKnownLocation(provider);
if(localisation != null){
handler.sendEmptyMessage(1);
}
// Critère de choix pour le meilleur fournisseur de localisation, ici NETWORK_PROVIDER
Criteria criteres = new Criteria();
provider = locationManager.getBestProvider(criteres, false);
// Mise à jour localisation
//locationManager.requestLocationUpdates(provider, updTime, udpDistance, ll);
};
};
thread.start();
}
public void onLocationChanged(Location pLocalisation) {
if(pLocalisation != null){
// Récupération convertion Lambert
double[] tabLambert = convertToLambert(pLocalisation);
((TextView)findViewById(R.id.textLambert)).setText(String.valueOf("Lat : " + floor(pLocalisation.getLatitude(), 5)+" - Lng : " + floor(pLocalisation.getLongitude(), 5)));
// Récupération convertion Dfci
String posDfci = convertToDfci(tabLambert[0], tabLambert[1]);
((TextView)findViewById(R.id.textDfci)).setText(String.valueOf(posDfci));
// Récupération cnvertion en degré en minutes et secondes
String posDms = convertToDms(pLocalisation.getLatitude(), pLocalisation.getLongitude());
((TextView)findViewById(R.id.textGeodesique)).setText(String.valueOf(posDms));
// Récupération adresse
convertAdresse(pLocalisation.getLatitude(), pLocalisation.getLongitude());
}
} |
Partager