Skip to content Skip to sidebar Skip to footer

Locationmanager's Location In Android Returns Null

I'm testing my Android app on a device, and it always fails when I use locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener); currentLocation

Solution 1:

GPS_PROVIDER may not work in bounded place, suppose inside a house or something like this. You should program it in such a way that if gps provider gives null location then you use network provider as a alternative although its accuracy is not so high. Here there is another issue. Your code should be as follows:

if(locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)
{
     locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener);
    currentLocation = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
}

Solution 2:

First of all, check that the GPS icon on device status bar has stopped blinking, marking you actually have GPS lock.

The call returns null if the location is not currently known, for example if you lack GPS lock.

Post a Comment for "Locationmanager's Location In Android Returns Null"