3

When setting up receiving location update with LocationServices.FusedLocationApi.requestLocationUpdates, I need to make sure I get at least one location.

For example, if the device has been still for a long time, after calling LocationServices.FusedLocationApi.requestLocationUpdates does it fire with last known location? Or do I have to call LocationServices.FusedLocationApi.getLastLocation too?

Don Box
  • 3,166
  • 3
  • 26
  • 55

1 Answers1

1

In my experience you must call LocationServices.FusedLocationApi.getLastLocation() to be guaranteed an immediate location object, and even that method may return null right after device reboot.

LocationServices.FusedLocationApi.requestLocationUpdates() will give you a call back 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 request a high accuracy location that requires GPS, and the GPS hasn't been used recently and the devices is in a location preventing GPS signal reception, you may not see a callback until the device obtains GPS signals again.

Sean Barbeau
  • 11,496
  • 8
  • 58
  • 111