私がしようとしているのは、ユーザーから位置を取得することです。まず、GPSを介して位置情報を取得しようとし、位置情報が利用可能かどうかをチェックします。そうでなければ、ネットワークタワーを通過しようとします。 GPSがオンになると正常に動作しています。私はオフにしたときにしかし、それはGPSがオンになっていなかったためセルタワーで位置を取得しようとしていますが、まだnullが返されます
manager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
provider = manager.getBestProvider(new Criteria(), false);
Log.i("ITEMSET best", provider);
manager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
// TODO: Consider calling
// ActivityCompat#requestPermissions
// here to request the missing permissions, and then overriding
// public void onRequestPermissionsResult(int requestCode, String[] permissions,
// int[] grantResults)
// to handle the case where the user grants the permission. See the documentation
// for ActivityCompat#requestPermissions for more details.
return;
}
Log.i("ITEMSET provider", provider);
location = manager.getLastKnownLocation(provider);
Log.i("ITEMSET netLoc", location + "");
if(location==null) {
provider = LocationManager.NETWORK_PROVIDER;
location = manager.getLastKnownLocation(provider);
Log.i("ITEMSET netLoc", location + "qqq");
}
Log.i("ITEMSET current", provider);
Log.i("ITEMSET location", location + "");
場所は、最初はnullたネットワークプロバイダを使用して場所を得ていないのGPS。しかし、プロバイダーをネットワークプロバイダーに変更しました。しかし、場所はまだヌル
詳細な位置情報は許可されていますか? –
はい私は素晴らしい場所と粗い場所の両方の権限を与えました。 –
あなたが場所の更新を要求していない可能性があります。その理由は、その問題を与える理由です。 –