LocationClient getLastLocation() return null
Currently the Fused Location Provider
will only maintain background location if at least one client is connected to it. Once the first client connects, it will immediately try to get a location. If your activity is the first client to connect and you call getLastLocation()
right away in onConnected()
, that might not be enough time for the first location to come in.
I had the same problem when following the instructions from the tutorial. On phone it worked and on the (Genymotion) emulator it didn't.
Solution
In your AndroidManifest.xml, change this:
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
to this:
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
...and you get the location immediately. No need to change your code (to listen to location updates).