Bonjour,
Pourriez-vous SVP tester ce code pour moi?
Dans le OnCreate:
Dans la classe principale:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9 // ------------------- // Initialisation Localisation // ------------------- LocationManager mlocManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); mlocManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, onLocationChange); Location lastloc = mlocManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); latitude = lastloc.getLatitude(); longitude = lastloc.getLongitude(); Log.e("TEST", "Location initale: " + longitude + "/" + latitude);
Dans le manifest j'ai une permission ACCESS_FINE_LOCATION et INTERNET.
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 /**************************** * Mise à jour position * ***************************/ LocationListener onLocationChange = new LocationListener() { @Override public void onLocationChanged(Location loc) { latitude = loc.getLatitude(); longitude = loc.getLongitude(); Log.e("TEST", "Changement de location: " + longitude + "/" + latitude); } @Override public void onProviderDisabled(String provider) {} @Override public void onProviderEnabled(String provider) {} @Override public void onStatusChanged(String provider, int status, Bundle extras) {} };
Parce que ce code m'affiche bien ma dernière position, mais ne se met jamais à jour (aucun Log de Changement de location), du moins sur mon téléphone...
Ça vous fait pareil?
Merci
Partager