Destination controller から Location controller へGPS信号シミュレーションを変更

This commit is contained in:
2024-04-09 15:06:41 +09:00
parent 8ad2e5988d
commit f6b2a6c7d4
9 changed files with 184 additions and 63 deletions

View File

@ -46,7 +46,8 @@ class DestinationController extends GetxController {
List<Destination> destinations = <Destination>[].obs; // 目的地のリストを保持するObservable変数です。
double currentLat = 0.0; // 現在の緯度と経度を保持する変数です。
double currentLon = 0.0;
double lastValidLat = 0.0; // 最後に中・強信号で拾ったGPS位置。ロゲ開始を屋内でやったら 0 のままなので、屋外で行うこと。
double lastValidLat = 0.0; // 最後に中・強信号で拾ったGPS位置。
// ロゲ開始を屋内でやったら 0 のままなので、屋外で行うこと。
double lastValidLon = 0.0;
DateTime lastGPSCollectedTime = DateTime.now(); // 最後にGPSデータが収集された時刻を保持する変数です。
@ -93,6 +94,7 @@ class DestinationController extends GetxController {
int chekcs = 0; // チェックポイントの数を保持する変数です。
var rogainingCounted = false.obs; // ロゲイニングがカウントされたかどうかを示すReactive変数です。
/*
//==== Akira .. GPS信号シミュレーション用 ===== ここから、2024-4-5
//
@ -106,6 +108,11 @@ class DestinationController extends GetxController {
isSimulationMode.value = value;
}
// 現在位置の取得メソッドを追加
LatLng getCurrentLocation() {
return LatLng(lastValidLat, lastValidLon);
}
//
// GPS信号の強弱を判断するメソッドを追加します。
//
@ -129,6 +136,7 @@ class DestinationController extends GetxController {
//
//==== Akira .. GPS信号シミュレーション用 ======= ここまで
*/
// 日時をフォーマットされた文字列に変換する関数です。
//
@ -919,6 +927,9 @@ class DestinationController extends GetxController {
// 要検討:エラーメッセージを表示するなどの適切な処理を追加することを検討してください。
//
// locationController からデバイスの受け取るGPS情報を取得し、
// handleLocationUpdate を呼び出している。
//
locationController.locationMarkerPositionStream.listen(
(locationMarkerPosition) {
if (locationMarkerPosition != null) {
@ -947,18 +958,17 @@ class DestinationController extends GetxController {
void handleLocationUpdate(LocationMarkerPosition? position) async {
try {
final DestinationController destinationController = Get.find<DestinationController>();
final signalStrength = destinationController.getGpsSignalStrength();
okToUseGPS = false;
double prevLat = lastValidLat; // 一つ前の位置情報を記録
double prevLon = lastValidLon;
//final signalStrength = locationController.getGpsSignalStrength();
if (position!=null && (signalStrength == 'high' || signalStrength == 'medium')) {
// 信号強度が高いまたは中程度の場合、現在の位置情報を更新
okToUseGPS = false;
double prevLat = currentLat; // 直前の位置
double prevLon = currentLon;
if (position!=null){
currentLat = position.latitude;
currentLon = position.longitude;
lastValidLat = position.latitude;
lastValidLon = position.longitude;
okToUseGPS = true;
} else {
// 信号強度が低い場合、最後に取得した高いまたは中程度の位置情報を使用
// 但し、最初から高精度のものがない場合、どうするか?
@ -1048,13 +1058,16 @@ class DestinationController extends GetxController {
return distanceToDest;
}
//final currentLocation = getCurrentLocation(); // GPS信号中以上での現在位置
Destination des = festuretoDestination(gfs);
//print("=== gfs == ${des.toMap()}");
var distance = const Distance();
distanceToDest = distance.as(LengthUnit.Meter,
LatLng(currentLat, currentLon), LatLng(des.lat!, des.lon!));
LatLng(currentLat,currentLon), LatLng(des.lat!, des.lon!));
// LatLng(currentLat, currentLon), LatLng(des.lat!, des.lon!));
//print("==== dist==${distanceToDest}");
return distanceToDest;
}
@ -1197,7 +1210,7 @@ class DestinationController extends GetxController {
//
void centerMapToCurrentLocation() {
assert(() {
print("center is ${currentLon}, ${currentLon}");
print("center is ${currentLat}, ${currentLon}");
return true;
}());
// Akira ... 状況によって呼ぶか呼ばないか

View File

@ -3,7 +3,7 @@ import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter_map/flutter_map.dart';
import 'package:flutter_map_location_marker/flutter_map_location_marker.dart';
import 'package:flutter_map_marker_popup/flutter_map_marker_popup.dart';
//import 'package:flutter_map_marker_popup/flutter_map_marker_popup.dart';
import 'package:flutter_polyline_points/flutter_polyline_points.dart';
import 'package:get/get.dart';
import 'package:latlong2/latlong.dart';
@ -22,7 +22,7 @@ class DestinationMapPage extends StatelessWidget {
final DestinationController destinationController =
Get.find<DestinationController>();
StreamSubscription? subscription;
final PopupController _popupLayerController = PopupController();
//final PopupController _popupLayerController = PopupController();
List<LatLng>? getPoints() {
//print("##### --- route point ${indexController.routePoints.length}");
@ -38,7 +38,7 @@ class DestinationMapPage extends StatelessWidget {
//
List<Marker>? getMarkers() {
List<Marker> pts = [];
int index = -1;
//int index = -1;
for (int i = 0; i < destinationController.destinations.length; i++) {
Destination d = destinationController.destinations[i];
//print("^^^^ $d ^^^^");
@ -151,10 +151,10 @@ class DestinationMapPage extends StatelessWidget {
bounds: indexController.currentBound.isNotEmpty
? indexController.currentBound[0]
: LatLngBounds.fromPoints([
LatLng(35.03999881162295, 136.40587119778962),
LatLng(36.642756778706904, 137.95226720406063)
const LatLng(35.03999881162295, 136.40587119778962),
const LatLng(36.642756778706904, 137.95226720406063)
]),
zoom: 1,
initialZoom: 1,
maxZoom: 42,
interactiveFlags: InteractiveFlag.pinchZoom | InteractiveFlag.drag,
),

View File

@ -47,7 +47,7 @@ class IndexController extends GetxController {
//final mapControllerReadyStream = Stream<bool>.value(false); // MapControllerの初期化状態を通知するためのストリーム
MapController mapController = MapController();
//MapController rogMapController = MapController();
MapController rogMapController = MapController();
String? userToken;

View File

@ -1,14 +1,9 @@
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:rogapp/model/destination.dart';
import 'package:rogapp/model/gps_data.dart';
import 'package:rogapp/pages/destination/destination_controller.dart';
import 'package:rogapp/pages/drawer/drawer_page.dart';
import 'package:rogapp/pages/index/index_controller.dart';
import 'package:rogapp/routes/app_pages.dart';
import 'package:rogapp/services/DatabaseService.dart';
import 'package:rogapp/utils/database_gps.dart';
import 'package:rogapp/utils/database_helper.dart';
import 'package:rogapp/widgets/list_widget.dart';
import 'package:rogapp/widgets/map_widget.dart';
import 'package:rogapp/utils/location_controller.dart';
@ -43,8 +38,8 @@ class IndexPage extends GetView<IndexController> {
//
@override
Widget build(BuildContext context) {
return WillPopScope(
onWillPop: () async => false,
return PopScope(
canPop: false,
child: Scaffold(
//
// Scaffoldウィジェットを使用して、アプリのメインページのレイアウトを構築しています。
@ -109,8 +104,7 @@ class IndexPage extends GetView<IndexController> {
// タップすることでGPS信号の強弱をシミュレーションできるようにする
// Akira 2024-4-5
//
Obx(
() => destinationController.isSimulationMode.value
Obx(() => locationController.isSimulationMode
? DropdownButton<String>(
value: locationController.getSimulatedSignalStrength(),
onChanged: (value) {