ACCESS_COARSE_LOCATION and ACCESS_FINE_LOCATON have both been included in the manifest. Also included in the Activity are:
import android.location.Location;
import android.location.LocationManager;
I have a listener for the nav drawer with the following class
private class DrawerItemClickListener implements ListView.OnItemClickListener {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
Location location = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
if (location != null)
{
final double longitude = location.getLongitude();
final double latitude = location.getLatitude();
}
selectItem(position);
}
}
From this, the location = null
, and thus would fail on location.getLongitude();
. I can of course avoid this with if (location != null)
, but I want the lat
and long
found.
Why is the location always null?