2

i'm working with android's location manager, and i notice that when I try to use requestLocationUpdates right after I turn on GPS, it gives a null location. how do i ensure I always get a valid location when i call requestlocationupdates?

my code is:

            //update the location
            locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, MIN_TIME_BW_UPDATES, MIN_DISTANCE_CHANGE_FOR_UPDATES, this);

            //get the location
            location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
broshen
  • 45
  • 3
  • Use the location from the `onLocationChanged()` callback, that's the only way to guarantee that you get a Location. The `getLastKnownLocation()` method can and will return null. – Daniel Nugent Apr 23 '16 at 05:18
  • @DanielNugent you should add as answer because it is right answer. – Talha Jul 18 '16 at 05:06

0 Answers0