非常に単純なコードを使用して、現在地の現在の座標を取得する単純なアプリを作成しました
public Location getLocation() {
lm = (LocationManager) mContext.getSystemService(LOCATION_SERVICE);
GPS = lm.isProviderEnabled(LocationManager.GPS_PROVIDER);
network = lm.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
if (!GPS && !network) {
showsettings();
} else {
Log.d("GPSClass", "GPS: " + GPS + " network: " + network);
this.canGetLocation = true;
if (network) {
lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER,
MIN_TIME, MIN_DISTANCE, this);
Log.d("GPSClass", "network");
location = lm
.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
if (location != null) {
return location;
}
}
if (GPS) {
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER,
MIN_TIME, MIN_DISTANCE, this);
Log.d("GPSClass", "GPS");
location = lm
.getLastKnownLocation(LocationManager.GPS_PROVIDER);
if (location != null) {
return location;
}
}
}
return null;
}
これはうまく機能しますが、その方法を理解できません。つまり、GPS がオフになっていて、すべての Wi-Fi とネットワークが切断されていても、正しい座標を取得できます。デバイスはどのように正しい座標を提供していますか (フライト モードでも)?