位置服务在真正的Android设备中不起作用

时间:2011-11-07 21:22:28

标签: android geolocation

我的测试应用程序找到设备的当前位置在模拟器中正常工作。也就是说,当我在Eclipse中的DDMS中,我将位置坐标发送到模拟器时,应用程序捕获广播并在模拟器中显示地图中的位置。但在我真正的2.3.3安卓设备中,应用程序只是挂起而gps在通知栏中闪烁。这是我在服务类中所做的事情

public void onStart(Intent intent, int startId) {
    super.onStart(intent, startId);
    Log.e("<<MyGpsService-onStart>>", "GPS starting...");
    triggerService = new Thread(new Runnable() {
        public void run() {
            try {
                Looper.prepare();
                lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
                myLocationListener = new GPSListener();
                long minTime = 10000; // frequency update: 10 seconds
                float minDistance = 50; // frequency update: 50 meter
                lm.requestLocationUpdates(
                        // request GPS updates
                        LocationManager.GPS_PROVIDER, minTime, minDistance,
                        myLocationListener);
                Looper.loop();
            } catch (Exception e) {
                Log.e("MYGPS", e.getMessage());
            }
        }// run
    });
    triggerService.start();
}
class GPSListener implements LocationListener {
    public void onLocationChanged(Location location) {
        double latitude = location.getLatitude();
        double longitude = location.getLongitude();

        Intent myFilteredResponse = new Intent(GPS_FILTER);
        myFilteredResponse.putExtra("latitude", latitude);
        myFilteredResponse.putExtra("longitude", longitude);
        Log.e(">>GPS_Service<<", "Lat:" + latitude + " lon:" + longitude);

        sendBroadcast(myFilteredResponse);
    }

    public void onProviderDisabled(String provider) {
    }

    public void onProviderEnabled(String provider) {
    }

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

我想知道你们是否有类似的问题。感谢。

更新:我按照以下问题回答:

Android - Reliably getting the current location

更改后,应用程序运行得更好。

2 个答案:

答案 0 :(得分:2)

你在设备的logcat中得到了什么有趣的东西吗?您可以使用adb查看实际设备的logcat。

答案 1 :(得分:2)

GPS无法在建筑物内部工作。 DDMS位置仅适用于模拟器