Android のバックグラウンドGPSを組み込み
This commit is contained in:
@ -112,7 +112,7 @@ class DestinationController extends GetxController {
|
||||
DateTime lastGPSDataReceivedTime = DateTime.now();
|
||||
DateTime lastPopupShownTime = DateTime.now().subtract(Duration(minutes: 10));
|
||||
bool isPopupShown = false;
|
||||
bool hasReceivedGPSData = false;
|
||||
bool hasReceivedGPSData = true;
|
||||
|
||||
var isCheckingIn = false.obs; // チェックイン操作中はtrueになり、重複してポップアップが出ないようにするもの。
|
||||
|
||||
@ -161,31 +161,36 @@ class DestinationController extends GetxController {
|
||||
*/
|
||||
|
||||
void showGPSDataNotReceivedPopup() {
|
||||
Get.dialog(
|
||||
AlertDialog(
|
||||
title: Text('GPS信号が受信できません'),
|
||||
content: Text('GPS信号が受信できる場所に移動してください。'),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Get.back(),
|
||||
child: Text('OK'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
if (Get.context != null) {
|
||||
Get.dialog(
|
||||
AlertDialog(
|
||||
title: Text('GPS信号が受信できません'),
|
||||
content: Text('GPS信号が受信できる場所に移動してください。'),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Get.back(),
|
||||
child: Text('OK'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
} else {
|
||||
// Get.contextがnullの場合の処理を追加
|
||||
print('GPS signal not received, but context is null');
|
||||
}
|
||||
}
|
||||
|
||||
// 最後に有効なGPSデータを受け取ってから10分以上経過している場合にのみメッセージを表示するようにします。
|
||||
//
|
||||
void checkGPSDataReceived() {
|
||||
if (!hasReceivedGPSData) {
|
||||
// GPS信号を全く受信していない。
|
||||
if (!isPopupShown) {
|
||||
// ポップアップしていない。
|
||||
showGPSDataNotReceivedPopup();
|
||||
lastPopupShownTime = DateTime.now();
|
||||
isPopupShown = true;
|
||||
}
|
||||
//debugPrint("GPS信号を全く受信していない。");
|
||||
if (!isPopupShown) {
|
||||
// ポップアップしていない。
|
||||
showGPSDataNotReceivedPopup();
|
||||
lastPopupShownTime = DateTime.now();
|
||||
isPopupShown = true;
|
||||
}
|
||||
} else {
|
||||
if (DateTime.now().difference(lastGPSDataReceivedTime).inSeconds >= 600) {
|
||||
// 前回GPS信号を受信してから10分経過。
|
||||
@ -946,7 +951,7 @@ class DestinationController extends GetxController {
|
||||
is_checkin: isCheckin,
|
||||
created_at: DateTime.now().millisecondsSinceEpoch);
|
||||
var res = await db.insertGps(gps_data);
|
||||
//debugPrint("Saved GPS data into DB...");
|
||||
debugPrint("Saved GPS data into DB...:${gps_data}");
|
||||
}
|
||||
} catch (err) {
|
||||
print("errr ready gps ${err}");
|
||||
@ -1188,7 +1193,7 @@ class DestinationController extends GetxController {
|
||||
// ゲームを開始する関数です。
|
||||
//
|
||||
Future<void> startGame() async {
|
||||
//print("------ starting game ------");
|
||||
debugPrint("------ starting game ------");
|
||||
if (game_started == false) {
|
||||
await checkForCheckin();
|
||||
}
|
||||
@ -1206,6 +1211,7 @@ class DestinationController extends GetxController {
|
||||
//
|
||||
bool inError=false;
|
||||
bool isRunningBackgroundGPS=false;
|
||||
int activeEngineCount = 0;
|
||||
|
||||
@override
|
||||
void onInit() async {
|
||||
@ -1215,6 +1221,8 @@ class DestinationController extends GetxController {
|
||||
|
||||
// MapControllerの初期化完了を待機するフラグを設定
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
//checkGPSDataReceived(); removed 2024-5-4
|
||||
|
||||
isMapControllerReady = true;
|
||||
});
|
||||
|
||||
@ -1280,7 +1288,7 @@ class DestinationController extends GetxController {
|
||||
|
||||
startGame();
|
||||
|
||||
checkGPSDataReceived();
|
||||
//checkGPSDataReceived();
|
||||
}
|
||||
|
||||
void restartGPS(){
|
||||
@ -1308,8 +1316,11 @@ class DestinationController extends GetxController {
|
||||
//
|
||||
double prevLat = 0.0; // 直前の位置
|
||||
double prevLon = 0.0;
|
||||
bool gpsDebugMode=false;
|
||||
|
||||
void handleLocationUpdate(LocationMarkerPosition? position) async {
|
||||
//debugPrint("DestinationController.handleLocationUpdate");
|
||||
|
||||
try {
|
||||
//final DestinationController destinationController = Get.find<DestinationController>();
|
||||
//final signalStrength = locationController.getGpsSignalStrength();
|
||||
@ -1399,7 +1410,7 @@ class DestinationController extends GetxController {
|
||||
lastGPSCollectedTime = DateTime.now();
|
||||
prevLat = position.latitude;
|
||||
prevLon = position.longitude;
|
||||
debugPrint("フロントエンドでのGPS保存(時間差:${difference.inSeconds}, 距離差:${distanceToDest}) : Time=${lastGPSCollectedTime}");
|
||||
gpsDebugMode ? debugPrint("フロントエンドでのGPS保存(時間差:${difference.inSeconds}, 距離差:${distanceToDest}) : Time=${lastGPSCollectedTime}"):null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user