これは、現在の場所を取得するために使用するコードです。
mgr = (LocationManager) getSystemService(LOCATION_SERVICE);
Criteria criteria = new Criteria();
best = mgr.getBestProvider(criteria, true);
if (best == null) {
//ask user to enable atleast one of the Location Providers
} else {
Location location = mgr.getLastKnownLocation(best);
//But sometimes it returns null
}
ほぼ毎回best = network
しかし、それは時々場所を提供していません。
mgr.getLastKnownLocation(best) returns null
また:
onResume() {
mgr.requestLocationUpdates(best, 15000, 10, this);
}
と
onPause() {
mgr.removeUpdates(this);
}
そのような場合の代替手段はありますか?
1つのオプションは
List<String> providers = mgr.getAllProviders();
すべてのプロバイダーを保存し、1つずつ実行します。しかし、これが推奨される場所を見たことがありません。さらに、最高のプロバイダーを求めることは、ドキュメントが示唆していることです。