ACCESS_COARSE_LOCATION 및 ACCESS_FINE_LOCATON이 모두 매니페스트에 포함되었습니다. 또한 활동에 포함됩니다 :null 포인터가 발생하는 GPS 정확성 부족
import android.location.Location;
import android.location.LocationManager;
나는 다음 클래스 이로부터
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);
}
}
의 location = null
으로 탐색 서랍 청취자를 가지고, 따라서 location.getLongitude();
에 실패합니다. 물론 if (location != null)
으로이를 피할 수는 있지만, lat
및 long
이 필요합니다.
위치가 항상 null입니까?
API 23 이상을 타겟팅합니까? [런타임에 권한 요청] (https://developer.android.com/training/permissions/requesting.html)을 어디에서합니까? – ianhanniballake