diff --git a/Mobile/android/app/src/main/AndroidManifest.xml b/Mobile/android/app/src/main/AndroidManifest.xml index df83995..311fc7c 100644 --- a/Mobile/android/app/src/main/AndroidManifest.xml +++ b/Mobile/android/app/src/main/AndroidManifest.xml @@ -1,6 +1,7 @@ - + + + NSLocationWhenInUseUsageDescription + This app needs access to location when open. CFBundleDevelopmentRegion $(DEVELOPMENT_LANGUAGE) CFBundleDisplayName diff --git a/Mobile/lib/main.dart b/Mobile/lib/main.dart index 51a0f96..c2de7f4 100644 --- a/Mobile/lib/main.dart +++ b/Mobile/lib/main.dart @@ -10,6 +10,7 @@ import 'login.dart'; import 'base/sidemenu.dart'; import 'profile.dart'; import 'models.dart'; +import 'package:geolocator/geolocator.dart'; import 'api.dart' as api; import 'package:http/http.dart' as http; @@ -51,8 +52,13 @@ class _MyHomePageState extends State { final GlobalKey _scaffoldKey = GlobalKey(); List _favorites = []; LatLng? _selectedPoint; + LatLng _currentPosition = LatLng(55.9397, 9.5156); double _zoom = 7.0; final TextEditingController searchBarInput =TextEditingController(text: ''); + final LocationSettings locationSettings = const LocationSettings( + accuracy: LocationAccuracy.high, + distanceFilter: 100, + ); void _onTap(TapPosition _, LatLng point) async { setState(() => _selectedPoint = point); @@ -223,6 +229,22 @@ class _MyHomePageState extends State { super.dispose(); } +@override + void initState() { + super.initState(); + _getCurrentLocation(); // Call the async method inside initState + } + + Future _getCurrentLocation() async { + await Geolocator.checkPermission(); + await Geolocator.requestPermission(); + Position position = await Geolocator.getCurrentPosition(desiredAccuracy: LocationAccuracy.best); + setState(() { + _currentPosition = LatLng(position.latitude, position.longitude); + _zoom = 5.0; + }); + } + @override Widget build(BuildContext context) { return SideMenu( @@ -233,15 +255,15 @@ class _MyHomePageState extends State { children: [ FlutterMap( options: MapOptions( - initialCenter: const LatLng(55.9397, 9.5156), + initialCenter: _currentPosition, initialZoom: _zoom, onTap: _onTap, onPositionChanged: (pos, _) => _zoom = pos.zoom, ), children: [ openStreetMapTileLayer, - if (_selectedPoint != null) MarkerLayer(markers: [ + if (_selectedPoint != null) Marker( point: _selectedPoint!, width: 30, @@ -253,7 +275,14 @@ class _MyHomePageState extends State { Icon(Icons.location_on_outlined, size: 30, color: Colors.black), ], ), - ) + ), + Marker( + point: _currentPosition, + width: 20, + height: 20, + alignment: Alignment.center, + child: const Icon(Icons.circle_sharp, size: 15, color: Colors.blueAccent), + ), ]), ..._favorites.map((favorite) => MarkerLayer( markers: [ @@ -301,12 +330,17 @@ class _MyHomePageState extends State { ), ], ), - Positioned( - right: 2, // Position the button at the bottom-right - bottom: 4.5, - child: ElevatedButton( - onPressed: GetOpenStreetMapArea, - child: const Text('Search'), + Positioned( + right: 2, // Position the button at the bottom-right + bottom: 4.5, + child: + SizedBox( + width: 100, + height: 28, + child: ElevatedButton( + onPressed: GetOpenStreetMapArea, + child: const Text('Search'), + ), ), ), ], @@ -314,6 +348,39 @@ class _MyHomePageState extends State { ), ), ), + Positioned( + right: 2, // Position the button at the bottom-right + bottom: 40, + child: + SizedBox( + width: 50, + height: 50, + child: Stack( + alignment: Alignment.center, + children: [ + const Icon( + Icons.circle, // Background circle icon + color: Colors.white, // Set the color of the circle + size: 48.0, // Adjust the size of the circle + ), + IconButton( + icon: const Icon( + Icons.my_location, // The main location icon + color: Colors.blue, // Customize the color + size: 36.0, // Customize the size + ), + onPressed: () { + // Your logic to get the current location goes here + _getCurrentLocation(); + }, + tooltip: 'Get Current Location', // Tooltip for the button + ), + ], + ) + + + ), + ), ], ), ), diff --git a/Mobile/macos/Flutter/GeneratedPluginRegistrant.swift b/Mobile/macos/Flutter/GeneratedPluginRegistrant.swift index b8e2b22..738f6dd 100644 --- a/Mobile/macos/Flutter/GeneratedPluginRegistrant.swift +++ b/Mobile/macos/Flutter/GeneratedPluginRegistrant.swift @@ -5,10 +5,12 @@ import FlutterMacOS import Foundation +import geolocator_apple import path_provider_foundation import shared_preferences_foundation func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { + GeolocatorPlugin.register(with: registry.registrar(forPlugin: "GeolocatorPlugin")) PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin")) SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin")) } diff --git a/Mobile/pubspec.lock b/Mobile/pubspec.lock index d73b93f..b5d1008 100644 --- a/Mobile/pubspec.lock +++ b/Mobile/pubspec.lock @@ -89,6 +89,14 @@ packages: url: "https://pub.dev" source: hosted version: "7.0.0" + fixnum: + dependency: transitive + description: + name: fixnum + sha256: "25517a4deb0c03aa0f32fd12db525856438902d9c16536311e76cdc57b31d7d1" + url: "https://pub.dev" + source: hosted + version: "1.1.0" flutter: dependency: "direct main" description: flutter @@ -120,6 +128,54 @@ packages: description: flutter source: sdk version: "0.0.0" + geolocator: + dependency: "direct main" + description: + name: geolocator + sha256: "0ec58b731776bc43097fcf751f79681b6a8f6d3bc737c94779fe9f1ad73c1a81" + url: "https://pub.dev" + source: hosted + version: "13.0.1" + geolocator_android: + dependency: transitive + description: + name: geolocator_android + sha256: "7aefc530db47d90d0580b552df3242440a10fe60814496a979aa67aa98b1fd47" + url: "https://pub.dev" + source: hosted + version: "4.6.1" + geolocator_apple: + dependency: transitive + description: + name: geolocator_apple + sha256: bc2aca02423ad429cb0556121f56e60360a2b7d694c8570301d06ea0c00732fd + url: "https://pub.dev" + source: hosted + version: "2.3.7" + geolocator_platform_interface: + dependency: transitive + description: + name: geolocator_platform_interface + sha256: "386ce3d9cce47838355000070b1d0b13efb5bc430f8ecda7e9238c8409ace012" + url: "https://pub.dev" + source: hosted + version: "4.2.4" + geolocator_web: + dependency: transitive + description: + name: geolocator_web + sha256: "2ed69328e05cd94e7eb48bb0535f5fc0c0c44d1c4fa1e9737267484d05c29b5e" + url: "https://pub.dev" + source: hosted + version: "4.1.1" + geolocator_windows: + dependency: transitive + description: + name: geolocator_windows + sha256: "53da08937d07c24b0d9952eb57a3b474e29aae2abf9dd717f7e1230995f13f0e" + url: "https://pub.dev" + source: hosted + version: "0.2.3" google_fonts: dependency: "direct main" description: @@ -397,6 +453,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.10.0" + sprintf: + dependency: transitive + description: + name: sprintf + sha256: "1fc9ffe69d4df602376b52949af107d8f5703b77cda567c4d7d86a0693120f23" + url: "https://pub.dev" + source: hosted + version: "7.0.0" stack_trace: dependency: transitive description: @@ -453,6 +517,14 @@ packages: url: "https://pub.dev" source: hosted version: "0.3.1" + uuid: + dependency: transitive + description: + name: uuid + sha256: "83d37c7ad7aaf9aa8e275490669535c8080377cfa7a7004c24dfac53afffaa90" + url: "https://pub.dev" + source: hosted + version: "4.4.2" vector_math: dependency: transitive description: @@ -473,10 +545,10 @@ packages: dependency: transitive description: name: web - sha256: "97da13628db363c635202ad97068d47c5b8aa555808e7a9411963c533b449b27" + sha256: d43c1d6b787bf0afad444700ae7f4db8827f701bc61c255ac8d328c6f4d52062 url: "https://pub.dev" source: hosted - version: "0.5.1" + version: "1.0.0" wkt_parser: dependency: transitive description: diff --git a/Mobile/pubspec.yaml b/Mobile/pubspec.yaml index 302ed3f..21732f9 100644 --- a/Mobile/pubspec.yaml +++ b/Mobile/pubspec.yaml @@ -39,6 +39,7 @@ dependencies: cupertino_icons: ^1.0.6 shared_preferences: ^2.3.2 google_fonts: ^6.2.1 + geolocator: ^13.0.1 dev_dependencies: flutter_test: diff --git a/Mobile/windows/flutter/generated_plugin_registrant.cc b/Mobile/windows/flutter/generated_plugin_registrant.cc index 8b6d468..1ece8f2 100644 --- a/Mobile/windows/flutter/generated_plugin_registrant.cc +++ b/Mobile/windows/flutter/generated_plugin_registrant.cc @@ -6,6 +6,9 @@ #include "generated_plugin_registrant.h" +#include void RegisterPlugins(flutter::PluginRegistry* registry) { + GeolocatorWindowsRegisterWithRegistrar( + registry->GetRegistrarForPlugin("GeolocatorWindows")); } diff --git a/Mobile/windows/flutter/generated_plugins.cmake b/Mobile/windows/flutter/generated_plugins.cmake index b93c4c3..7f101a7 100644 --- a/Mobile/windows/flutter/generated_plugins.cmake +++ b/Mobile/windows/flutter/generated_plugins.cmake @@ -3,6 +3,7 @@ # list(APPEND FLUTTER_PLUGIN_LIST + geolocator_windows ) list(APPEND FLUTTER_FFI_PLUGIN_LIST