CPラベルが1文字しか出ない、起動が遅い

This commit is contained in:
2024-04-14 20:16:13 +09:00
parent f6b2a6c7d4
commit 4ef42216f8
18 changed files with 1520 additions and 372 deletions

View File

@ -35,9 +35,6 @@ class LocationController extends GetxController {
StreamSubscription<Position>? positionStream;
// 位置情報のストリームを保持する変数です。StreamSubscription<Position>型で宣言されています。
//===== Akira Added 2024-4-9 start
// GPSシミュレーション用の変数を追加
bool isSimulationMode = true;
LatLng? lastValidLocation;
// GPSシミュレーション用のメソッドを追加
@ -45,13 +42,52 @@ class LocationController extends GetxController {
isSimulationMode = value;
}
String latestSignalStrength="low";
// ====== Akira , GPS信号強度をシミュレート ==== ここから
//
//===== Akira Added 2024-4-9 start
// GPSシミュレーション用の変数を追加 ===> 本番では false にする。
bool isSimulationMode = true;
// GPS信号強度をシミュレートするための変数
final Rx<String> _simulatedSignalStrength = Rx<String>('low');
// GPS信号強度をシミュレートするための関数
void setSimulatedSignalStrength(String strength) {
if( strength!='real') {
isSimulationMode = true;
_simulatedSignalStrength.value = strength;
latestSignalStrength.value = strength;
}else{
isSimulationMode = false;
_simulatedSignalStrength.value = strength;
}
}
// シミュレートされた信号強度を取得するための関数
String getSimulatedSignalStrength() {
debugPrint("strength : ${_simulatedSignalStrength.value}");
return _simulatedSignalStrength.value;
}
//
// ====== Akira , GPS信号強度をシミュレート ==== ここまで
// GPS信号が弱い場合のフラグ. 本番では、true,high にする。
bool isGpsSignalWeak = true;
RxString latestSignalStrength = 'low'.obs;
//final _latestSignalStrength = 'low'.obs; // 初期値を設定
//String get latestSignalStrength => _latestSignalStrength.value;
Stream<String> get gpsSignalStrengthStream => latestSignalStrength.stream;
// GPS信号の強弱を判断するメソッドを追加. 10m 以内強、30m以内中、それ以上
//
String getGpsSignalStrength(Position? position) {
if (position == null) {
latestSignalStrength="low";
latestSignalStrength.value = "low";
isGpsSignalWeak = true;
return 'low';
}
final accuracy = position.accuracy;
@ -59,13 +95,16 @@ class LocationController extends GetxController {
return _simulatedSignalStrength.value; // GPS信号強度シミュレーション
}else {
if (accuracy <= 10) {
latestSignalStrength="high";
latestSignalStrength.value = "high";
isGpsSignalWeak = false;
return 'high';
} else if (accuracy <= 30) {
latestSignalStrength="medium";
latestSignalStrength.value = "medium";
isGpsSignalWeak = false;
return 'medium';
} else {
latestSignalStrength="low";
latestSignalStrength.value = "low";
isGpsSignalWeak = true;
return 'low';
}
}
@ -74,11 +113,18 @@ class LocationController extends GetxController {
// 現在位置を調整するメソッドを追加
LatLng? adjustCurrentLocation(Position? position) {
if (position == null) {
return null;
if( lastValidLocation!=null ) {
//debugPrint("=== adjustCurrentLocation (Position:Null and using LastValidLocation ${lastValidLocation})===");
return LatLng(lastValidLocation!.latitude, lastValidLocation!.longitude);
}else {
print("=== adjustCurrentLocation (Position:Null and No LastValidLocation ... )===");
return null;
}
//return lastValidLocation ?? LatLng(0, 0);
}
final signalStrength = getGpsSignalStrength(position);
if (signalStrength == 'high' || signalStrength == 'medium') {
//debugPrint("=== adjustCurrentLocation (Position:Get and return Valid location:${position} ... )===");
lastValidLocation = LatLng(position.latitude, position.longitude);
}
return lastValidLocation ?? LatLng(position.latitude, position.longitude);
@ -93,25 +139,6 @@ class LocationController extends GetxController {
bool isStreamPaused = false; // 位置情報のストリームが一時停止中かどうかを示すフラグです。bool型で宣言されています。
// ====== Akira , GPS信号強度をシミュレート ==== ここから
//
// GPS信号強度をシミュレートするための変数
final Rx<String> _simulatedSignalStrength = Rx<String>('high');
// GPS信号強度をシミュレートするための関数
void setSimulatedSignalStrength(String strength) {
_simulatedSignalStrength.value = strength;
}
// シミュレートされた信号強度を取得するための関数
String getSimulatedSignalStrength() {
return _simulatedSignalStrength.value;
}
//
// ====== Akira , GPS信号強度をシミュレート ==== ここから
// 位置マーカーの位置情報のストリームを取得するゲッター関数です。
// locationMarkerPositionStreamController.streamを返します。
//
@ -223,7 +250,7 @@ class LocationController extends GetxController {
return;
}
// 位置情報の設定を行います。
// 位置情報の設定を行います。z11
// Set up the location options
const locationOptions =
LocationSettings(accuracy: LocationAccuracy.high, distanceFilter: 0);
@ -235,38 +262,30 @@ class LocationController extends GetxController {
//
positionStream = Geolocator.getPositionStream(locationSettings: locationOptions).listen(
(Position? position) {
final signalStrength = getGpsSignalStrength(position);
if (signalStrength == 'low') {
isGpsSignalWeak = true;
} else {
isGpsSignalWeak = false;
}
final adjustedLocation = adjustCurrentLocation(position);
if (adjustedLocation!=null) {
if (adjustedLocation != null) {
final locationMarkerPosition = LocationMarkerPosition(
latitude: adjustedLocation.latitude,
longitude: adjustedLocation.longitude,
accuracy: position?.accuracy ?? 0,
);
locationMarkerPositionStreamController.add(locationMarkerPosition);
}else{
handleLocationUpdate(locationMarkerPosition);
//locationMarkerPositionStreamController.add(locationMarkerPosition); // 位置データ送信
} else {
// 位置情報が取得できなかった場合、
// locationMarkerPositionStreamControllerにnullを追加します。
locationMarkerPositionStreamController.add(null);
locationMarkerPositionStreamController.add(null); // null 送信?
//forceUpdateLocation(Position? position);
}
/*
if (position != null) {
// ストリームから位置情報を受信した場合、
// LocationMarkerPositionオブジェクトを作成し、
// locationMarkerPositionStreamControllerに追加します。
//
final LocationMarkerPosition locationMarkerPosition =
LocationMarkerPosition(
latitude: position.latitude,
longitude: position.longitude,
accuracy: position.accuracy);
locationMarkerPositionStreamController.add(locationMarkerPosition);
} else {
// 位置情報が取得できなかった場合、
// locationMarkerPositionStreamControllerにnullを追加します。
locationMarkerPositionStreamController.add(null);
}
*/
},
},
onError: (e) {
// エラーが発生した場合、locationMarkerPositionStreamControllerにエラーを追加します。
locationMarkerPositionStreamController.addError(e);
@ -314,6 +333,36 @@ class LocationController extends GetxController {
}
}
void handleLocationUpdate(LocationMarkerPosition? position) async {
if (position != null) {
/*
currentPosition.value = position;
final locationMarkerPosition = LocationMarkerPosition(
latitude: position.latitude,
longitude: position.longitude,
accuracy: position.accuracy,
);
*/
locationMarkerPositionStreamController.add(position);
}
}
// このメソッドは、現在の位置情報を locationMarkerPositionStreamController に送信します。
//
void forceUpdateLocation(Position? position) {
if (position != null) {
final adjustedLocation = adjustCurrentLocation(position);
if (adjustedLocation != null) {
final locationMarkerPosition = LocationMarkerPosition(
latitude: adjustedLocation.latitude,
longitude: adjustedLocation.longitude,
accuracy: position.accuracy,
);
locationMarkerPositionStreamController.add(locationMarkerPosition);
}
}
}
// コントローラーのクローズ時に呼び出されるライフサイクルメソッドです。
// positionStreamをキャンセルします。
//