0
ロケーションマネージャーでユーザーの場所を取得しようとしていますが、その場所は常にnullを返します。また、gpsをオンにするようにユーザーに依頼しています。Androidロケーションマネージャーで緯度と経度を取得
これは私のコードです:
int permisioncheck = ContextCompat.checkSelfPermission(getActivity(), Manifest.permission.ACCESS_FINE_LOCATION);
if(permisioncheck == 0){
lm = (LocationManager)getContext().getSystemService(Context.LOCATION_SERVICE);
List<String> providers = lm.getProviders(true);
Location bestLocation = null;
for (String provider : providers) {
Location location = lm.getLastKnownLocation(provider);
if (location == null) {
continue;
}
if (bestLocation == null || location.getAccuracy() < bestLocation.getAccuracy()) {
// Found best last known location: %s", l);
bestLocation = location;
}
}
if(bestLocation == null){
System.out.println("is NULL!");
}
}else{
ActivityCompat.requestPermissions(getActivity(), new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, 1);
}
私は誰かが、おかげでエラーを見つけるために私を助けることができることを願っています。
@OusmaneMahyDiawさらに質問に追加する必要があるものは何ですか?実質的にそれはすべて私のコードです –