At least one location sent by location services after calling requestLocationUpdates?

When configuring to update the recipient location with using, LocationServices.FusedLocationApi.requestLocationUpdates

I need to make sure I get at least one location.

For example, if the device is still for a long time, after the call, LocationServices.FusedLocationApi.requestLocationUpdates

it starts up with the last known location? Or do I need to call as well LocationServices.FusedLocationApi.getLastLocation

?

+3


source to share


1 answer


In my experience, you have to call LocationServices.FusedLocationApi.getLastLocation()

for a guaranteed immediate location object, and even this method can return null

immediately after device reboot.



LocationServices.FusedLocationApi.requestLocationUpdates()

will give you a callback with a location when a new or relatively recent location is available that matches your request parameters in terms of accuracy, energy, etc., but if no location that matches your parameters is available, it may not call back for a while. For example, if you are requesting a high-precision location that requires GPS, and the GPS has not been used recently, and the devices are in a location that prevents GPS reception, you may not see the callback until the device receives GPS signals again.

+1


source







All Articles