2023-12-06 11:16:17 +05:30
|
|
|
|
import 'dart:async';
|
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
|
import 'package:get/get.dart';
|
|
|
|
|
|
import 'package:geolocator/geolocator.dart';
|
2024-04-09 15:06:41 +09:00
|
|
|
|
import 'package:latlong2/latlong.dart';
|
|
|
|
|
|
//import 'package:rogapp/widgets/debug_widget.dart';
|
2024-03-06 11:40:00 +05:30
|
|
|
|
import 'package:flutter_map_location_marker/flutter_map_location_marker.dart';
|
2024-04-20 12:34:49 +09:00
|
|
|
|
import 'package:rogapp/pages/destination/destination_controller.dart';
|
2023-12-06 11:16:17 +05:30
|
|
|
|
|
2024-04-07 10:56:51 +09:00
|
|
|
|
// LocationControllerクラスは、GetxControllerを継承したクラスであり、位置情報の管理を担当しています。
|
|
|
|
|
|
// LocationControllerは以下の機能を提供しています。
|
|
|
|
|
|
// LocationControllerは、アプリ全体で位置情報を一元管理するための重要なコンポーネントです。
|
|
|
|
|
|
// 他のコンポーネントは、LocationControllerから位置情報を取得し、位置情報に関連する機能を実装することができます。
|
|
|
|
|
|
//
|
2024-04-09 15:06:41 +09:00
|
|
|
|
// Features:
|
2024-04-07 10:56:51 +09:00
|
|
|
|
// * 現在の位置情報を保持し、他のコンポーネントからアクセスできるようにします。
|
|
|
|
|
|
// * 位置情報のストリームを管理し、位置情報の更新を監視します。
|
|
|
|
|
|
// * 位置情報サービスの有効性と権限の確認を行い、適切な処理を行います。
|
|
|
|
|
|
// * 位置情報のストリームを開始、停止、再開する機能を提供します。
|
|
|
|
|
|
// * 位置マーカーの位置情報をStreamControllerを通じて他のコンポーネントに通知します。
|
|
|
|
|
|
//
|
2024-04-09 15:06:41 +09:00
|
|
|
|
// Logic:
|
|
|
|
|
|
// 1. startPositionStreamメソッドで、Geolocator.getPositionStreamを使用して位置情報のストリームを開始します。
|
|
|
|
|
|
// 2. ストリームから位置情報を受信すると、LocationMarkerPositionオブジェクトを作成し、locationMarkerPositionStreamControllerに追加します。
|
|
|
|
|
|
// 3. 位置情報が取得できなかった場合や、エラーが発生した場合は、適切な処理を行います。
|
|
|
|
|
|
// 4. stopPositionStreamメソッドで、位置情報のストリームを一時停止することができます。
|
|
|
|
|
|
// 5. resumePositionStreamメソッドで、一時停止中の位置情報のストリームを再開することができます。
|
|
|
|
|
|
// 6. onCloseメソッドで、コントローラーのクローズ時に位置情報のストリームをキャンセルします。
|
|
|
|
|
|
//
|
2023-12-06 11:16:17 +05:30
|
|
|
|
class LocationController extends GetxController {
|
|
|
|
|
|
// Reactive variable to hold the current position
|
2024-04-07 10:56:51 +09:00
|
|
|
|
Rx<Position?> currentPosition = Rx<Position?>(null);
|
|
|
|
|
|
// 現在の位置情報を保持するReactive変数です。Rx<Position?>型で宣言されています。
|
2023-12-06 11:16:17 +05:30
|
|
|
|
|
|
|
|
|
|
// Subscription to the position stream
|
2024-04-07 10:56:51 +09:00
|
|
|
|
StreamSubscription<Position>? positionStream;
|
|
|
|
|
|
// 位置情報のストリームを保持する変数です。StreamSubscription<Position>型で宣言されています。
|
2024-03-06 11:40:00 +05:30
|
|
|
|
|
2024-04-09 15:06:41 +09:00
|
|
|
|
LatLng? lastValidLocation;
|
2024-04-20 17:30:26 +09:00
|
|
|
|
DateTime lastGPSDataReceivedTime = DateTime.now(); // 最後にGPSデータを受け取った時刻
|
2024-04-09 15:06:41 +09:00
|
|
|
|
|
|
|
|
|
|
// GPSシミュレーション用のメソッドを追加
|
|
|
|
|
|
void setSimulationMode(bool value) {
|
|
|
|
|
|
isSimulationMode = value;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-04-14 20:16:13 +09:00
|
|
|
|
// ====== 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() {
|
2024-04-20 12:34:49 +09:00
|
|
|
|
//debugPrint("strength : ${_simulatedSignalStrength.value}");
|
2024-04-14 20:16:13 +09:00
|
|
|
|
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;
|
|
|
|
|
|
|
2024-04-09 15:06:41 +09:00
|
|
|
|
|
|
|
|
|
|
// GPS信号の強弱を判断するメソッドを追加. 10m 以内:強、30m以内:中、それ以上:弱
|
|
|
|
|
|
//
|
|
|
|
|
|
String getGpsSignalStrength(Position? position) {
|
|
|
|
|
|
if (position == null) {
|
2024-04-14 20:16:13 +09:00
|
|
|
|
latestSignalStrength.value = "low";
|
|
|
|
|
|
isGpsSignalWeak = true;
|
2024-04-09 15:06:41 +09:00
|
|
|
|
return 'low';
|
|
|
|
|
|
}
|
|
|
|
|
|
final accuracy = position.accuracy;
|
|
|
|
|
|
if(isSimulationMode){
|
|
|
|
|
|
return _simulatedSignalStrength.value; // GPS信号強度シミュレーション
|
|
|
|
|
|
}else {
|
|
|
|
|
|
if (accuracy <= 10) {
|
2024-04-14 20:16:13 +09:00
|
|
|
|
latestSignalStrength.value = "high";
|
|
|
|
|
|
isGpsSignalWeak = false;
|
2024-04-09 15:06:41 +09:00
|
|
|
|
return 'high';
|
|
|
|
|
|
} else if (accuracy <= 30) {
|
2024-04-14 20:16:13 +09:00
|
|
|
|
latestSignalStrength.value = "medium";
|
|
|
|
|
|
isGpsSignalWeak = false;
|
2024-04-09 15:06:41 +09:00
|
|
|
|
return 'medium';
|
|
|
|
|
|
} else {
|
2024-04-14 20:16:13 +09:00
|
|
|
|
latestSignalStrength.value = "low";
|
|
|
|
|
|
isGpsSignalWeak = true;
|
2024-04-09 15:06:41 +09:00
|
|
|
|
return 'low';
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 現在位置を調整するメソッドを追加
|
|
|
|
|
|
LatLng? adjustCurrentLocation(Position? position) {
|
|
|
|
|
|
if (position == null) {
|
2024-04-14 20:16:13 +09:00
|
|
|
|
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;
|
|
|
|
|
|
}
|
2024-04-09 15:06:41 +09:00
|
|
|
|
//return lastValidLocation ?? LatLng(0, 0);
|
|
|
|
|
|
}
|
|
|
|
|
|
final signalStrength = getGpsSignalStrength(position);
|
|
|
|
|
|
if (signalStrength == 'high' || signalStrength == 'medium') {
|
2024-04-14 20:16:13 +09:00
|
|
|
|
//debugPrint("=== adjustCurrentLocation (Position:Get and return Valid location:${position} ... )===");
|
2024-04-09 15:06:41 +09:00
|
|
|
|
lastValidLocation = LatLng(position.latitude, position.longitude);
|
|
|
|
|
|
}
|
|
|
|
|
|
return lastValidLocation ?? LatLng(position.latitude, position.longitude);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//===== Akira Added 2024-4-9 end
|
|
|
|
|
|
|
2024-03-06 11:40:00 +05:30
|
|
|
|
final locationMarkerPositionStreamController =
|
|
|
|
|
|
StreamController<LocationMarkerPosition?>.broadcast();
|
2024-04-07 10:56:51 +09:00
|
|
|
|
// 位置マーカーの位置情報を送信するためのStreamControllerです。
|
|
|
|
|
|
// StreamController<LocationMarkerPosition?>型で宣言されています。
|
2024-03-06 11:40:00 +05:30
|
|
|
|
|
2024-04-07 10:56:51 +09:00
|
|
|
|
bool isStreamPaused = false; // 位置情報のストリームが一時停止中かどうかを示すフラグです。bool型で宣言されています。
|
2023-12-06 11:16:17 +05:30
|
|
|
|
|
2024-04-07 10:56:51 +09:00
|
|
|
|
// 位置マーカーの位置情報のストリームを取得するゲッター関数です。
|
|
|
|
|
|
// locationMarkerPositionStreamController.streamを返します。
|
|
|
|
|
|
//
|
2024-03-06 11:40:00 +05:30
|
|
|
|
Stream<LocationMarkerPosition?> get locationMarkerPositionStream =>
|
|
|
|
|
|
locationMarkerPositionStreamController.stream;
|
|
|
|
|
|
|
2024-04-07 10:56:51 +09:00
|
|
|
|
// コントローラーの初期化時に呼び出されるライフサイクルメソッドです。
|
|
|
|
|
|
// startPositionStreamメソッドを呼び出して、位置情報のストリームを開始します。
|
|
|
|
|
|
//
|
2023-12-06 11:16:17 +05:30
|
|
|
|
@override
|
|
|
|
|
|
void onInit() {
|
|
|
|
|
|
super.onInit();
|
|
|
|
|
|
// Start listening to location updates when the controller is initialized
|
2024-04-07 10:56:51 +09:00
|
|
|
|
startPositionStream();
|
|
|
|
|
|
|
2023-12-06 11:16:17 +05:30
|
|
|
|
}
|
|
|
|
|
|
|
2024-04-07 10:56:51 +09:00
|
|
|
|
// 位置情報のストリームを開始するメソッドです。
|
|
|
|
|
|
// 位置情報サービスが有効か確認し、無効な場合はダイアログを表示します。
|
|
|
|
|
|
// 位置情報の権限を確認し、必要な権限がない場合は権限をリクエストします。
|
|
|
|
|
|
// 既存の位置情報のストリームをキャンセルします。
|
|
|
|
|
|
// Geolocator.getPositionStreamを使用して、新しい位置情報のストリームを開始します。
|
|
|
|
|
|
// ストリームから受信した位置情報をlocationMarkerPositionStreamControllerに追加します。
|
|
|
|
|
|
// エラーが発生した場合は、locationMarkerPositionStreamControllerにエラーを追加します。
|
|
|
|
|
|
// ストリームが一時停止中の場合は、ストリームを再開します。
|
|
|
|
|
|
//
|
2024-04-09 01:58:25 +09:00
|
|
|
|
// 2024-4-8 Akira : See 2809
|
|
|
|
|
|
// stopPositionStreamメソッドを追加して、既存のストリームをキャンセルするようにしました。また、ストリームが完了したらnullに設定し、エラー発生時にストリームをキャンセルするようにしました。
|
|
|
|
|
|
//
|
2023-12-06 11:16:17 +05:30
|
|
|
|
void startPositionStream() async {
|
|
|
|
|
|
// Check for location service and permissions before starting the stream
|
2024-04-09 15:06:41 +09:00
|
|
|
|
// 位置情報サービスの有効性をチェックし、無効な場合はエラーハンドリングを行います。
|
|
|
|
|
|
//
|
2023-12-06 11:16:17 +05:30
|
|
|
|
bool serviceEnabled = await Geolocator.isLocationServiceEnabled();
|
|
|
|
|
|
if (!serviceEnabled) {
|
|
|
|
|
|
// Use GetX's context to show a dialog
|
|
|
|
|
|
Get.dialog(
|
|
|
|
|
|
AlertDialog(
|
|
|
|
|
|
title: const Text('Location Services Disabled'),
|
|
|
|
|
|
content: const Text(
|
|
|
|
|
|
'Please enable location services to continue using the app.'),
|
|
|
|
|
|
actions: <Widget>[
|
|
|
|
|
|
TextButton(
|
|
|
|
|
|
child: const Text('OK'),
|
|
|
|
|
|
onPressed: () {
|
|
|
|
|
|
// Close the dialog
|
|
|
|
|
|
Get.back();
|
|
|
|
|
|
// Optionally, you can direct the user to the settings page
|
|
|
|
|
|
// Geolocator.openLocationSettings();
|
|
|
|
|
|
},
|
|
|
|
|
|
),
|
|
|
|
|
|
],
|
|
|
|
|
|
),
|
|
|
|
|
|
barrierDismissible: false, // User must tap button to close dialog
|
|
|
|
|
|
);
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-04-09 15:06:41 +09:00
|
|
|
|
// 位置情報の権限をチェックし、拒否されている場合はエラーハンドリングを行います。
|
|
|
|
|
|
//
|
2023-12-06 11:16:17 +05:30
|
|
|
|
LocationPermission permission = await Geolocator.checkPermission();
|
|
|
|
|
|
if (permission == LocationPermission.denied) {
|
|
|
|
|
|
permission = await Geolocator.requestPermission();
|
|
|
|
|
|
if (permission == LocationPermission.denied) {
|
|
|
|
|
|
// Show a dialog if permissions are still denied
|
|
|
|
|
|
Get.dialog(
|
|
|
|
|
|
AlertDialog(
|
|
|
|
|
|
title: const Text('Location Permission Denied'),
|
|
|
|
|
|
content: const Text(
|
|
|
|
|
|
'This app requires location permissions to function properly. Please enable location permissions in your device settings.'),
|
|
|
|
|
|
actions: <Widget>[
|
|
|
|
|
|
TextButton(
|
|
|
|
|
|
child: const Text('OK'),
|
|
|
|
|
|
onPressed: () {
|
|
|
|
|
|
// Close the dialog
|
|
|
|
|
|
Get.back();
|
|
|
|
|
|
// Optionally, direct the user to the app settings
|
|
|
|
|
|
// Geolocator.openAppSettings();
|
|
|
|
|
|
},
|
|
|
|
|
|
),
|
|
|
|
|
|
],
|
|
|
|
|
|
),
|
|
|
|
|
|
barrierDismissible: false,
|
|
|
|
|
|
);
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (permission == LocationPermission.deniedForever) {
|
|
|
|
|
|
// Show a dialog if permissions are permanently denied
|
|
|
|
|
|
Get.dialog(
|
|
|
|
|
|
AlertDialog(
|
|
|
|
|
|
title: const Text('Location Permission Needed'),
|
|
|
|
|
|
content: const Text(
|
|
|
|
|
|
'Location permissions have been permanently denied. Please open app settings to enable location permissions.'),
|
|
|
|
|
|
actions: <Widget>[
|
|
|
|
|
|
TextButton(
|
|
|
|
|
|
child: const Text('Open Settings'),
|
|
|
|
|
|
onPressed: () {
|
|
|
|
|
|
// Close the dialog and open app settings
|
|
|
|
|
|
Get.back();
|
|
|
|
|
|
Geolocator.openAppSettings();
|
|
|
|
|
|
},
|
|
|
|
|
|
),
|
|
|
|
|
|
],
|
|
|
|
|
|
),
|
|
|
|
|
|
barrierDismissible: false,
|
|
|
|
|
|
);
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-04-14 20:16:13 +09:00
|
|
|
|
// 位置情報の設定を行います。z11
|
2023-12-06 11:16:17 +05:30
|
|
|
|
// Set up the location options
|
2023-12-07 10:20:44 +05:30
|
|
|
|
const locationOptions =
|
2024-03-06 11:40:00 +05:30
|
|
|
|
LocationSettings(accuracy: LocationAccuracy.high, distanceFilter: 0);
|
|
|
|
|
|
|
2024-04-09 15:06:41 +09:00
|
|
|
|
// 既存の位置情報のストリームをキャンセルします。
|
2024-03-06 11:40:00 +05:30
|
|
|
|
await positionStream?.cancel();
|
2023-12-07 10:20:44 +05:30
|
|
|
|
|
2024-04-09 15:06:41 +09:00
|
|
|
|
// 新しい位置情報のストリームを開始します。
|
|
|
|
|
|
//
|
2024-04-09 01:58:25 +09:00
|
|
|
|
positionStream = Geolocator.getPositionStream(locationSettings: locationOptions).listen(
|
2024-03-06 11:40:00 +05:30
|
|
|
|
(Position? position) {
|
2024-04-14 20:16:13 +09:00
|
|
|
|
final signalStrength = getGpsSignalStrength(position);
|
|
|
|
|
|
if (signalStrength == 'low') {
|
|
|
|
|
|
isGpsSignalWeak = true;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
isGpsSignalWeak = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-04-20 12:34:49 +09:00
|
|
|
|
final DestinationController destinationController = Get.find<DestinationController>();
|
|
|
|
|
|
|
|
|
|
|
|
// ロゲ開始前、終了後、GPS=low の場合は更新しない。
|
|
|
|
|
|
//
|
2024-04-24 11:30:38 +09:00
|
|
|
|
if (isGpsSignalWeak == false) {
|
|
|
|
|
|
//if (destinationController.isInRog.value && isGpsSignalWeak == false) {
|
|
|
|
|
|
final adjustedLocation = adjustCurrentLocation(position);
|
|
|
|
|
|
if (adjustedLocation != null) {
|
|
|
|
|
|
final locationMarkerPosition = LocationMarkerPosition(
|
|
|
|
|
|
latitude: adjustedLocation.latitude,
|
|
|
|
|
|
longitude: adjustedLocation.longitude,
|
|
|
|
|
|
accuracy: position?.accuracy ?? 0,
|
|
|
|
|
|
);
|
|
|
|
|
|
handleLocationUpdate(locationMarkerPosition);
|
|
|
|
|
|
//locationMarkerPositionStreamController.add(locationMarkerPosition); // 位置データ送信
|
|
|
|
|
|
} else {
|
|
|
|
|
|
// 位置情報が取得できなかった場合、
|
|
|
|
|
|
// locationMarkerPositionStreamControllerにnullを追加します。
|
|
|
|
|
|
locationMarkerPositionStreamController.add(null); // null 送信?
|
|
|
|
|
|
//forceUpdateLocation(Position? position);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
//}else{
|
|
|
|
|
|
// debugPrint("GPS処理対象外");
|
|
|
|
|
|
|
2024-04-09 15:06:41 +09:00
|
|
|
|
}
|
2024-04-20 12:34:49 +09:00
|
|
|
|
|
2024-04-14 20:16:13 +09:00
|
|
|
|
},
|
2024-04-09 01:58:25 +09:00
|
|
|
|
onError: (e) {
|
2024-04-09 15:06:41 +09:00
|
|
|
|
// エラーが発生した場合、locationMarkerPositionStreamControllerにエラーを追加します。
|
2024-04-09 01:58:25 +09:00
|
|
|
|
locationMarkerPositionStreamController.addError(e);
|
|
|
|
|
|
},
|
|
|
|
|
|
onDone: () {
|
|
|
|
|
|
positionStream = null; // ストリームが完了したらnullに設定
|
|
|
|
|
|
},
|
|
|
|
|
|
cancelOnError: true // エラー発生時にストリームをキャンセル
|
2024-03-06 11:40:00 +05:30
|
|
|
|
);
|
2023-12-06 11:16:17 +05:30
|
|
|
|
|
|
|
|
|
|
// Resume stream if it was paused previously
|
2024-04-09 15:06:41 +09:00
|
|
|
|
// ストリームが一時停止中の場合、ストリームを再開します。
|
|
|
|
|
|
//
|
2023-12-06 11:16:17 +05:30
|
|
|
|
if (isStreamPaused) {
|
|
|
|
|
|
isStreamPaused = false;
|
2024-03-06 11:40:00 +05:30
|
|
|
|
positionStream!.resume();
|
2023-12-06 11:16:17 +05:30
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Method to stop the position stream
|
2024-04-07 10:56:51 +09:00
|
|
|
|
// 位置情報のストリームを停止するメソッドです。
|
|
|
|
|
|
// positionStreamが存在する場合、ストリームを一時停止します。
|
|
|
|
|
|
// isStreamPausedフラグをtrueに設定します。
|
|
|
|
|
|
//
|
2024-04-09 01:58:25 +09:00
|
|
|
|
void stopPositionStream() async {
|
2023-12-06 11:16:17 +05:30
|
|
|
|
if (positionStream != null) {
|
2024-04-09 01:58:25 +09:00
|
|
|
|
// updated Akira 2024-4-8
|
|
|
|
|
|
await positionStream!.cancel();
|
|
|
|
|
|
positionStream = null;
|
|
|
|
|
|
|
|
|
|
|
|
//positionStream!.pause();
|
|
|
|
|
|
//isStreamPaused = true;
|
2023-12-06 11:16:17 +05:30
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Method to resume the position stream
|
2024-04-07 10:56:51 +09:00
|
|
|
|
// 位置情報のストリームを再開するメソッドです。
|
|
|
|
|
|
// positionStreamが存在し、ストリームが一時停止中の場合、ストリームを再開します。
|
|
|
|
|
|
// isStreamPausedフラグをfalseに設定します。
|
|
|
|
|
|
//
|
2023-12-06 11:16:17 +05:30
|
|
|
|
void resumePositionStream() {
|
|
|
|
|
|
if (positionStream != null && isStreamPaused) {
|
|
|
|
|
|
positionStream!.resume();
|
|
|
|
|
|
isStreamPaused = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-04-14 20:16:13 +09:00
|
|
|
|
void handleLocationUpdate(LocationMarkerPosition? position) async {
|
|
|
|
|
|
if (position != null) {
|
2024-04-20 12:34:49 +09:00
|
|
|
|
//debugPrint("position = ${position}");
|
2024-04-14 20:16:13 +09:00
|
|
|
|
/*
|
|
|
|
|
|
currentPosition.value = position;
|
|
|
|
|
|
final locationMarkerPosition = LocationMarkerPosition(
|
|
|
|
|
|
latitude: position.latitude,
|
|
|
|
|
|
longitude: position.longitude,
|
|
|
|
|
|
accuracy: position.accuracy,
|
|
|
|
|
|
);
|
|
|
|
|
|
*/
|
2024-04-20 17:30:26 +09:00
|
|
|
|
lastGPSDataReceivedTime = DateTime.now(); // 最後にGPS信号を受け取った時刻
|
2024-04-14 20:16:13 +09:00
|
|
|
|
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);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-04-07 10:56:51 +09:00
|
|
|
|
// コントローラーのクローズ時に呼び出されるライフサイクルメソッドです。
|
|
|
|
|
|
// positionStreamをキャンセルします。
|
|
|
|
|
|
//
|
2023-12-06 11:16:17 +05:30
|
|
|
|
@override
|
|
|
|
|
|
void onClose() {
|
|
|
|
|
|
// Cancel the position stream subscription when the controller is closed
|
|
|
|
|
|
positionStream?.cancel();
|
|
|
|
|
|
super.onClose();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|