I tried to get the current location using android studio but always the variable currentLocation has null value
and the android studio draw red line under
Location currentLocation= LocationServices.FusedLocationApi.getLastLocation(mLocationclient);
and asked to check the permission I tried two ways with checking permission and without but the same result return null value
please who can help me? this is the code I have used
private GoogleApiClient mLocationclient;
mLocationclient=new GoogleApiClient.Builder(this)
.addApi(LocationServices.API)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
mLocationclient.connect();
Location currentLocation= LocationServices.FusedLocationApi.getLastLocation(mLocationclient);
if(currentLocation==null)
Toast.makeText(this,"could not connect",Toast.LENGTH_SHORT).show();
else {
LatLng ll=new LatLng(
currentLocation.getLatitude(),
currentLocation.getLongitude()
);
CameraUpdate update=CameraUpdateFactory.newLatLngZoom(ll,50);
mMap.animateCamera(update);
}
please help me.