いつものように新しい場所を取得しますか? onCreate
ここでこのコードを使用しています
locationManager = (LocationManager) this.getSystemService(LOCATION_SERVICE);
isGPSEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
isNetworkEnabled = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
if (isGPSEnabled) {
if (location == null) {
provider = LocationManager.GPS_PROVIDER;
locationManager.requestLocationUpdates(provider, 500, 0, this);
if (locationManager != null) {
location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
if (location != null) {
latLng = new LatLng(location.getLatitude(), location.getLongitude());
if (location != null) {
ParseQueryMap();
}
}
}
}
}
if (isNetworkEnabled){
if (location == null) {
provider = LocationManager.NETWORK_PROVIDER;
locationManager.requestLocationUpdates(provider, 500, 0, this);
if (locationManager != null) {
location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
if (location != null) {
latLng = new LatLng(location.getLatitude(), location.getLongitude());
if (location != null) {
ParseQueryMap();
}
}
}
}
}
}
アプリケーションを実行したときにその場所が利用できない場合、以前に知られていた場所 ( getLastKnownLocation()
) が使用されます。私はこの解決策が好きではありません。すぐに、または一定時間 (約 5 秒) 後にアプリケーションを実行して、正確な位置を表示する必要があります。起動時の正確な位置は、ベースの最も近いポイントを表示する必要があります。出来ますか?助けてくれてありがとう