Как получить Местоположение только через GPS без какого-либо подключения к Интернету.Я использую приведенный ниже код, чтобы получить местоположение, но не работаю без Интернета.Пожалуйста, дайте мне знать, почему я не получаю местоположение без интернета
boolean isGPSEnabled = manager
.isProviderEnabled(LocationManager.GPS_PROVIDER);
boolean isNetworkEnabled = manager
.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
if (!isGPSEnabled && !isNetworkEnabled) {
// no network provider is enabled
} else {
// First get location from Network Provider
if (isNetworkEnabled) {
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
}
manager.requestLocationUpdates(
LocationManager.NETWORK_PROVIDER,
MIN_TIME_BW_UPDATES,
MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
Log.d("Network", "Network");
if (manager != null) {
location = manager
.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
if (location != null) {
currentLatitude = location.getLatitude();
currentLongitude = location.getLongitude();
}
}
}
// if GPS Enabled get lat/long using GPS Services
if (isGPSEnabled) {
if (location == null) {
manager.requestLocationUpdates(
LocationManager.GPS_PROVIDER,
MIN_TIME_BW_UPDATES,
MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
Log.d("GPS Enabled", "GPS Enabled");
if (manager != null) {
location = manager
.getLastKnownLocation(LocationManager.GPS_PROVIDER);
if (location != null) {
currentLatitude = location.getLatitude();
currentLongitude = location.getLongitude();
}
}
}
}
Log.d(TAG, "getLocation: "+currentLatitude+" "+currentLongitude);
}
} catch (Exception e) {
e.printStackTrace();
}