IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

API standards et tierces Android Discussion :

[Localisation GPS - ANDROID 2.2] Acquisition et rapidité


Sujet :

API standards et tierces Android

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre confirmé
    Homme Profil pro
    Développeur Web
    Inscrit en
    Octobre 2008
    Messages
    103
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 51
    Localisation : France, Var (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Développeur Web

    Informations forums :
    Inscription : Octobre 2008
    Messages : 103
    Par défaut [Localisation GPS - ANDROID 2.2] Acquisition et rapidité
    Bonjour,

    Je fais suite à la discussion : http://www.developpez.net/forums/d10...tion-rapidite/

    Je voudrais arriver à appliquer cette méthode :

    1 - Récupération de la dernière position connue + traitement
    2 - Récupération de la position via le réseau
    3 - Récupération de la position via le GPS
    4 - A la réception de la position via le réseau, Affichage + rayon d'approximation assez grand
    5 - A la réception de la position via le GPS, Affichage + rayon d'approximation plus restreint.

    Ci dessous mon code, je tourne en rond avec mon thread, mon GPS_Provider dont je ne sais pas ou mettre et mon requestLocationUpdates().

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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());			
    		}		
    	}
    Un coups de pouce ?

  2. #2
    Expert confirmé

    Avatar de Feanorin
    Profil pro
    Inscrit en
    Avril 2004
    Messages
    4 589
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2004
    Messages : 4 589
    Par défaut
    Bonjour,

    Ci dessous mon code, je tourne en rond avec mon thread, mon GPS_Provider dont je ne sais pas ou mettre et mon requestLocationUpdates().
    Place le quand tu veux lancer le GPS , soit je pense dans le onCreate.

Discussions similaires

  1. Application Android Localisation GPS
    Par hafid8h dans le forum API standards et tierces
    Réponses: 10
    Dernier message: 15/08/2014, 15h38
  2. Localisation sur Android
    Par TDDev dans le forum Android
    Réponses: 1
    Dernier message: 09/05/2011, 11h42
  3. [Localisation GPS] Problème d'acquisition et de rapidité
    Par mamatt dans le forum API standards et tierces
    Réponses: 10
    Dernier message: 06/04/2011, 22h39
  4. Fermer la localisation GPS
    Par alec.po dans le forum API standards et tierces
    Réponses: 2
    Dernier message: 09/09/2010, 12h50
  5. Localisation avec android
    Par jimi154 dans le forum Android
    Réponses: 7
    Dernier message: 18/05/2010, 09h26

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo