2013-06-27 4 views
1

Je veux recevoir des mises à jour du GPS, mais je ne peux pas. La méthode onLocationChanged n'appelle pas. Dans cette application, j'utilise aussi l'API Google Maps. Je ne sais pas, c'est peut-être une cause de mes problèmes.Les mises à jour GPS ne sont pas appelées

Il est le code sur le GPS dans MainActivity:

LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); 

final LocationListener locationListener = new LocationListener() { 
      public void onLocationChanged(Location location) 
      { 
         txtLat.setText("Latitude: " + String.valueOf((int)(location.getLatitude())) + "," 
           + String.valueOf(((location.getLatitude() * 100) % 100)) + " degrees"); 

        txtLong.setText("Longtitude: " + String.valueOf((int)(location.getLongitude())) + "," 
           + String.valueOf(((location.getLongitude() * 100) % 100)) + " degrees"); 

      } 
public void onStatusChanged(String provider, int status, Bundle extras) {} 

      public void onProviderEnabled(String provider) {} 

      public void onProviderDisabled(String provider) {} 
      }; 

locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener); 

et Manifest i ont déclaré ces autorisations:

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> 
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/> 
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" /> 

et d'autres que l'API Google Maps v2 requise

EDIT: LogCat :

06-27 14:25:28.785: D/dalvikvm(5206): GC_FOR_ALLOC freed 42K, 8% free 2500K/2716K, paused 42ms, total 48ms 
06-27 14:25:28.836: I/dalvikvm-heap(5206): Grow heap (frag case) to 6.147MB for 3712016-byte allocation 
06-27 14:25:28.906: D/dalvikvm(5206): GC_FOR_ALLOC freed 2K, 4% free 6122K/6344K, paused 64ms, total 64ms 
06-27 14:25:28.965: D/dalvikvm(5206): GC_CONCURRENT freed <1K, 4% free 6122K/6344K, paused 8ms+5ms, total 66ms 
06-27 14:25:29.595: D/dalvikvm(5206): GC_CONCURRENT freed 3766K, 53% free 3523K/7464K, paused 24ms+46ms, total 149ms 
06-27 14:25:30.025: D/dalvikvm(5206): GC_CONCURRENT freed 243K, 51% free 3681K/7464K, paused 5ms+5ms, total 52ms 
06-27 14:25:30.045: E/Google Maps Android API(5206): Google Maps Android API v2 only supports devices with OpenGL ES 2.0 and above 
06-27 14:25:30.385: D/dalvikvm(5206): GC_FOR_ALLOC freed 146K, 49% free 3826K/7464K, paused 39ms, total 40ms 
06-27 14:25:30.685: D/dalvikvm(5206): GC_CONCURRENT freed 82K, 44% free 4234K/7464K, paused 16ms+26ms, total 133ms 
06-27 14:25:31.066: D/libEGL(5206): Emulator without GPU support detected. Fallback to software renderer. 
06-27 14:25:31.095: I/Choreographer(5206): Skipped 77 frames! The application may be doing too much work on its main thread. 
06-27 14:25:31.115: D/libEGL(5206): loaded /system/lib/egl/libGLES_android.so 
06-27 14:25:31.175: D/gralloc_goldfish(5206): Emulator without GPU emulation detected. 
06-27 14:25:31.819: D/dalvikvm(5206): GC_CONCURRENT freed 402K, 41% free 4428K/7464K, paused 30ms+60ms, total 386ms 
06-27 14:25:31.915: D/dalvikvm(5206): WAIT_FOR_CONCURRENT_GC blocked 428ms 
06-27 14:25:32.427: D/dalvikvm(5206): GC_CONCURRENT freed 630K, 41% free 4429K/7464K, paused 31ms+18ms, total 100ms 
06-27 14:25:32.427: D/dalvikvm(5206): WAIT_FOR_CONCURRENT_GC blocked 59ms 
06-27 14:33:03.695: E/Trace(5381): error opening trace file: No such file or directory (2) 
06-27 14:33:04.395: D/dalvikvm(5381): GC_FOR_ALLOC freed 46K, 9% free 2500K/2720K, paused 42ms, total 45ms 
06-27 14:33:04.435: I/dalvikvm-heap(5381): Grow heap (frag case) to 6.147MB for 3712016-byte allocation 
06-27 14:33:04.485: D/dalvikvm(5381): GC_FOR_ALLOC freed 2K, 4% free 6122K/6348K, paused 43ms, total 44ms 
06-27 14:33:04.555: D/dalvikvm(5381): GC_CONCURRENT freed <1K, 4% free 6122K/6348K, paused 5ms+5ms, total 70ms 
06-27 14:33:05.235: D/dalvikvm(5381): GC_CONCURRENT freed 3774K, 53% free 3500K/7448K, paused 20ms+84ms, total 157ms 
06-27 14:33:05.615: D/dalvikvm(5381): GC_CONCURRENT freed 232K, 51% free 3663K/7448K, paused 72ms+5ms, total 118ms 
06-27 14:33:05.645: E/Google Maps Android API(5381): Google Maps Android API v2 only supports devices with OpenGL ES 2.0 and above 
06-27 14:33:05.875: D/dalvikvm(5381): GC_FOR_ALLOC freed 190K, 49% free 3847K/7448K, paused 39ms, total 40ms 
06-27 14:33:06.268: D/dalvikvm(5381): GC_CONCURRENT freed 62K, 44% free 4223K/7448K, paused 71ms+77ms, total 284ms 
06-27 14:33:06.815: D/libEGL(5381): Emulator without GPU support detected. Fallback to software renderer. 
06-27 14:33:06.865: D/libEGL(5381): loaded /system/lib/egl/libGLES_android.so 
06-27 14:33:06.906: I/Choreographer(5381): Skipped 120 frames! The application may be doing too much work on its main thread. 
06-27 14:33:07.005: D/gralloc_goldfish(5381): Emulator without GPU emulation detected. 
06-27 14:33:07.455: I/Choreographer(5381): Skipped 38 frames! The application may be doing too much work on its main thread. 
06-27 14:33:07.545: D/dalvikvm(5381): GC_CONCURRENT freed 381K, 41% free 4427K/7448K, paused 8ms+111ms, total 349ms 
06-27 14:33:07.545: D/dalvikvm(5381): WAIT_FOR_CONCURRENT_GC blocked 237ms 
06-27 14:33:08.246: D/dalvikvm(5381): GC_CONCURRENT freed 630K, 41% free 4430K/7448K, paused 72ms+7ms, total 171ms 
06-27 14:33:08.246: D/dalvikvm(5381): WAIT_FOR_CONCURRENT_GC blocked 32ms 
+1

mettre les journaux dans les rappels, sont-ils appelés? –

+1

Etes-vous dehors en faisant cela? Voyez-vous un signal GPS stable au lieu d'un signal clignotant? – Carnal

+0

As-tu assez attendu? Le GPS a besoin de temps, surtout si vous êtes à l'intérieur – EMarci15

Répondre

1

Si vous tentez de récupérer l'emplacement à l'aide du fournisseur GPS et que vous êtes dans un bâtiment ou que vous avez une mauvaise réception GPS, onLocationChanged ne sera jamais appelé.

Il n'y aura pas de repli automatique vers le Wifi ou le celltower.

Vérifiez toujours quel type de fournisseur vous utilisez, même lorsque vous spécifiez des critères.

Google a publié un lot de new Location APIs via Google Play Services qui offre des moyens plus efficaces de récupération de l'emplacement de l'utilisateur (amélioration de la précision et de la durée de vie de la batterie).

Je vous suggère de jeter un oeil à ceux-ci et suivez le tutoriel Retrieving the Current Location (il comprend un exemple d'application que vous pouvez télécharger).

Questions connexes