I am trying to get the last known location of the user.
After Google API is connected, I call my function:
@Override
public void onConnected(Bundle bundle) {
initilizeMap();
}
The function looks like this:
private void initilizeMap(){
mLastLocation = LocationServices.FusedLocationApi
.getLastLocation(mGoogleApiClient);
if (mLastLocation != null){
...
}else{
// location unknown
}
}
I opened up the Google maps first to get the current location of the user. However, mLastLocation
is still null.
The most interesting thing is that the code is working on Sony tablet. But I changed my phone today to Nexus and it is not working on this device!
How can I fix this?
P.S. I included these permissions in my manifest file:
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
and android version is 6.0.1