I can get my location on my real Galaxy S6+ but I on my Android 4.4.4 Galaxy S5 Emulator, I hit "mLastLocation is null"
In my emulator, the location service is On and the "Location last reported" is of the current day.
The emulator logs show me :
05-12 22:57:13.481: W/GCoreFlp(766): No location to retu for getLastLocation()
Here's the code :
onCreate ...
if (mGoogleApiClient == null) {
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addCoectionCallbacks(this)
.addOnCoectionFailedListener(this)
.addApi(LocationServices.API)
.build();
}
@Override
public void onCoected(Bundle bundle) {
if (ContextCompat.checkSelfPermission(this,
android.Manifest.permission.ACCESS_FINE_LOCATION)
!= PackageManager.PERMISSION_GRANTED) {
// Should we show an explanation?
if (ActivityCompat.shouldShowRequestPermissionRationale(this,
android.Manifest.permission.ACCESS_FINE_LOCATION)) {
}
else {
ActivityCompat.requestPermissions(this,
new String[]{android.Manifest.permission.ACCESS_FINE_LOCATION},
8);
}
}
if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED
&& ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
Log.d("Splash", " PERMISSION PROBLEM");
retu;
}
Location mLastLocation = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);
if (mLastLocation != null) {
Log.d("Splash", "Latitude : " + String.valueOf(mLastLocation.getLatitude()));
Log.d("Splash", "Longitude : " + String.valueOf(mLastLocation.getLongitude()));
}else{
Log.d("Splash" ,"mLastLocation is null");
}
}
