Question

I'm trying to retrieve the device's current location using the device's GPS. When I register for updates (as shown below) for LocationManager.GPS_PROVIDER no updates are rolling, yet when I do the same for LocationManager.NETWORK_PROVIDER I get the updates.

I have tested it on my Android device (not the emulator). I have also made sure the GPS is on. Other apps (not mine) are able to access my location. What am I missing here?

LocationListener locationListener = new LocationListener() {
    @Override
    public void onLocationChanged(Location location) {
            locationRetrieved(location, this);
    }

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

    public void onProviderEnabled(String provider) { }

    public void onProviderDisabled(String provider) { providerDisabled(); }
};

locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener);
Was it helpful?

Solution

GPS start up is not an instant process. The receiver basically has to know the position of each of the GPS satellites in the constellation in order to calculate it's location

Are you first checking if there is a last known location which you can use? Most apps first check for it and then search for a location.

OTHER TIPS

You should check wheter your phone is allowing the gathering of location with GPS.

Probabily what is happening is that in Settings -> Location you only have the checkbox for wireless location. If so, the GPS_PROVIDER doesn't work.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top