1

My test app that finds current location of the device is working fine in emulator. That is, when in my DDMS in eclipse, I send the location coordinates to the emulator, the app catches the broadcast and displays the location in the map in emulator. But in my real 2.3.3 android device, the app just hangs while gps is blinking in notification bar. Here is what I am doing in my service class

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

I wonder if any of you have a similar problem. Thanks.

UPDATE: I followed following question and answer:

Android - Reliably getting the current location

After the change, the app is working a lot better.

Community
  • 1
  • 1
Tae-Sung Shin
  • 20,215
  • 33
  • 138
  • 240
  • 1
    When GPS is blinking it means that you do not have a GPS lock (Normally from poor signal due to being inside). Have you tried standing outside and waiting to get the lock? The GPS icon will stop flashing and go solid once you do this. – dymmeh Nov 07 '11 at 21:29
  • 1
    Thanks for your comment. Now I am getting the coordinates of incorrect location. The location in the map is away from 5 miles from here. Maybe it's again a signal issue. But when I try google map, it shows correct place. – Tae-Sung Shin Nov 07 '11 at 21:43
  • You should probably create some threshold and keep listening until your location falls within it (i.e. location.getAccuracy()). Then stop listening for location. – Damian Nov 07 '11 at 21:53
  • 1
    Oh well, it turned out my fault in calculation. I accidentally made the coordinates integers resulting in wrong place. – Tae-Sung Shin Nov 08 '11 at 00:10

2 Answers2

2

Are you getting anything interesting in the logcat for your device? You can view the logcat of the actual device using adb.

Kurtis Nusbaum
  • 30,445
  • 13
  • 78
  • 102
2

GPS does not work inside buildings. DDMS location only works for the emulator

Fernando Gallego
  • 4,064
  • 31
  • 50