サイドメニューの改善、ログイン直後にマップが表示されない問題、屋内でGPS信号が受信できない場合のポップアップ追加
This commit is contained in:
@ -104,6 +104,13 @@ class DestinationController extends GetxController {
|
||||
// ゴール地点でのロジックの制御:rogainingCountedがtrueの場合、つまりポイントがカウントされている場合にのみ、ゴール処理を実行できます。
|
||||
// UI の更新:rogainingCountedの状態に基づいて、適切なメッセージやボタンを表示することができます。
|
||||
|
||||
bool isMapControllerReady = false;
|
||||
|
||||
LatLng lastValidGPSLocation = LatLng(0, 0);
|
||||
DateTime lastGPSDataReceivedTime = DateTime.now();
|
||||
DateTime lastPopupShownTime = DateTime.now().subtract(Duration(minutes: 10));
|
||||
bool isPopupShown = false;
|
||||
bool hasReceivedGPSData = false;
|
||||
|
||||
/*
|
||||
//==== Akira .. GPS信号シミュレーション用 ===== ここから、2024-4-5
|
||||
@ -149,6 +156,48 @@ class DestinationController extends GetxController {
|
||||
//==== Akira .. GPS信号シミュレーション用 ======= ここまで
|
||||
*/
|
||||
|
||||
void showGPSDataNotReceivedPopup() {
|
||||
Get.dialog(
|
||||
AlertDialog(
|
||||
title: Text('GPS信号が受信できません'),
|
||||
content: Text('GPS信号が受信できる場所に移動してください。'),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Get.back(),
|
||||
child: Text('OK'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// 最後に有効なGPSデータを受け取ってから10分以上経過している場合にのみメッセージを表示するようにします。
|
||||
//
|
||||
void checkGPSDataReceived() {
|
||||
if (!hasReceivedGPSData) {
|
||||
// GPS信号を全く受信していない。
|
||||
if (!isPopupShown) {
|
||||
// ポップアップしていない。
|
||||
showGPSDataNotReceivedPopup();
|
||||
lastPopupShownTime = DateTime.now();
|
||||
isPopupShown = true;
|
||||
}
|
||||
} else {
|
||||
if (DateTime.now().difference(lastGPSDataReceivedTime).inSeconds >= 600) {
|
||||
// 前回GPS信号を受信してから10分経過。
|
||||
if (!isPopupShown && DateTime.now().difference(lastPopupShownTime).inMinutes >= 3) {
|
||||
// 前回ポップアップしてから3分経過してなければ
|
||||
showGPSDataNotReceivedPopup();
|
||||
lastPopupShownTime = DateTime.now();
|
||||
isPopupShown = true;
|
||||
}
|
||||
} else {
|
||||
isPopupShown = false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// 日時をフォーマットされた文字列に変換する関数です。
|
||||
//
|
||||
String getFormatedTime(DateTime datetime) {
|
||||
@ -1014,12 +1063,27 @@ class DestinationController extends GetxController {
|
||||
}
|
||||
}
|
||||
|
||||
Timer? gpsCheckTimer; // 一定間隔でGPSデータの受信状態をチェックするタイマー
|
||||
|
||||
void startGPSCheckTimer() {
|
||||
gpsCheckTimer = Timer.periodic(Duration(seconds: 5), (timer) {
|
||||
checkGPSDataReceived();
|
||||
});
|
||||
}
|
||||
|
||||
// コントローラーの初期化時に呼び出されるライフサイクルメソッドです。
|
||||
//
|
||||
@override
|
||||
void onInit() async {
|
||||
super.onInit();
|
||||
|
||||
startGPSCheckTimer();
|
||||
|
||||
// MapControllerの初期化完了を待機するフラグを設定
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
isMapControllerReady = true;
|
||||
});
|
||||
|
||||
// 要検討:エラーメッセージを表示するなどの適切な処理を追加することを検討してください。
|
||||
//
|
||||
// locationController からデバイスの受け取るGPS情報を取得し、
|
||||
@ -1035,13 +1099,17 @@ class DestinationController extends GetxController {
|
||||
});
|
||||
|
||||
startGame();
|
||||
|
||||
checkGPSDataReceived();
|
||||
}
|
||||
|
||||
// コントローラーのクローズ時に呼び出されるライフサイクルメソッドです。
|
||||
//
|
||||
@override
|
||||
void onClose() {
|
||||
gpsCheckTimer?.cancel();
|
||||
locationController.stopPositionStream();
|
||||
super.onClose();
|
||||
}
|
||||
|
||||
// 位置情報の更新を処理する関数です。
|
||||
@ -1062,11 +1130,25 @@ class DestinationController extends GetxController {
|
||||
if (position != null) {
|
||||
currentLat = position.latitude;
|
||||
currentLon = position.longitude;
|
||||
lastValidGPSLocation = LatLng(currentLat, currentLon);
|
||||
okToUseGPS = true;
|
||||
lastGPSDataReceivedTime = DateTime.now();
|
||||
hasReceivedGPSData = true;
|
||||
|
||||
} else {
|
||||
checkGPSDataReceived();
|
||||
|
||||
// 信号強度が低い場合、最後に取得した高いまたは中程度の位置情報を使用
|
||||
// 但し、最初から高精度のものがない場合、どうするか?
|
||||
//
|
||||
// GPSデータが受信できない場合、最後に有効なGPSデータを使用
|
||||
position = LocationMarkerPosition(
|
||||
latitude: lastValidGPSLocation.latitude,
|
||||
longitude: lastValidGPSLocation.longitude,
|
||||
accuracy: 0,
|
||||
);
|
||||
|
||||
/*
|
||||
if (lastValidLat != 0.0 && lastValidLon != 0.0) {
|
||||
currentLat = lastValidLat;
|
||||
currentLon = lastValidLon;
|
||||
@ -1085,6 +1167,7 @@ class DestinationController extends GetxController {
|
||||
backgroundColor: Colors.yellow,
|
||||
);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
if (okToUseGPS && position != null) {
|
||||
@ -1103,7 +1186,7 @@ class DestinationController extends GetxController {
|
||||
Duration difference = lastGPSCollectedTime.difference(DateTime.now())
|
||||
.abs();
|
||||
// 最後にGPS信号を取得した時刻から10秒以上経過、かつ10m以上経過(普通に歩くスピード)
|
||||
if (difference.inSeconds >= 10 || distanceToDest >= 10) {
|
||||
if (difference.inSeconds >= 10 && distanceToDest >= 10) {
|
||||
// print(
|
||||
// "^^^^^^^^ GPS data collected ${DateFormat('kk:mm:ss \n EEE d MMM').format(DateTime.now())}, ^^^ ${position.latitude}, ${position.longitude}");
|
||||
|
||||
@ -1259,21 +1342,29 @@ class DestinationController extends GetxController {
|
||||
void fixMapBound(String token) {
|
||||
//String _token = indexController.currentUser[0]["token"];
|
||||
indexController.switchPage(AppPages.INDEX);
|
||||
LocationService.getLocationsExt(token).then((value) {
|
||||
if (value != null) {
|
||||
//print("--- loc ext is - $value ----");
|
||||
LatLngBounds bnds = LatLngBounds(
|
||||
LatLng(value[1], value[0]), LatLng(value[3], value[2]));
|
||||
//print("--- bnds is - $bnds ----");
|
||||
indexController.mapController.fitBounds(
|
||||
bnds,
|
||||
);
|
||||
indexController.currentBound.clear();
|
||||
indexController.currentBound.add(bnds);
|
||||
indexController.loadLocationsBound();
|
||||
centerMapToCurrentLocation();
|
||||
}
|
||||
});
|
||||
|
||||
if (isMapControllerReady) {
|
||||
LocationService.getLocationsExt(token).then((value) {
|
||||
if (value != null) {
|
||||
//print("--- loc ext is - $value ----");
|
||||
LatLngBounds bnds = LatLngBounds(
|
||||
LatLng(value[1], value[0]), LatLng(value[3], value[2]));
|
||||
//print("--- bnds is - $bnds ----");
|
||||
indexController.mapController.fitBounds(
|
||||
bnds,
|
||||
);
|
||||
indexController.currentBound.clear();
|
||||
indexController.currentBound.add(bnds);
|
||||
indexController.loadLocationsBound();
|
||||
centerMapToCurrentLocation();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
// MapControllerの初期化が完了していない場合は、遅延して再試行
|
||||
Future.delayed(Duration(milliseconds: 100), () {
|
||||
fixMapBound(token);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user