I try to access the last known location in a Fragment as explained here
in my onCreate:
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mGoogleApiClient = new GoogleApiClient.Builder(getActivity())
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(LocationServices.API)
.build();
}
in my onResume:
@Override
public void onResume() {
super.onResume();
mGoogleApiClient.connect();
}
The Fragment implements GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener
and the on Connected is called!!
@Override
public void onConnected(Bundle bundle) {
mLastLocation = LocationServices.FusedLocationApi.getLastLocation(
mGoogleApiClient);
if (mLastLocation != null) {
}
}
and the mLastLocation is always null. Everytime I try to call GetLastLocation() it returns null.
Any idea why?