不会调用GPS更新

时间:2013-06-27 14:13:00

标签: android gps

我想从GPS接收更新,但我不能。方法onLocationChanged没有调用。在此应用程序中,我也使用Google Maps API。我不知道,也许这是我的问题的原因。

这是关于MainActivity中GPS的代码:

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);

并且在Manifest中我声明了这些权限:

<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" />

以及Google Maps API v2所需的其他内容

编辑: 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 个答案:

答案 0 :(得分:1)

如果您尝试使用GPS提供商检索位置,并且您在建筑物内或有糟糕的GPS接收,则永远不会调用onLocationChanged。

Wifi或celltower不会自动回退。

即使在指定条件时,也要检查您使用的提供商类型。

Google通过Google Play服务发布了一大堆new Location APIs,提供了更有效的方法来检索用户位置(提高准确性和电池续航时间)。

我建议您查看这些内容并按照Retrieving the Current Location教程(包括可下载的示例应用)。